Commit 1ebd3b04 authored by Phil Willoughby's avatar Phil Willoughby Committed by Facebook Github Bot

mark lock holders with nodiscard

Summary: Acquiring a lock into an unused temporary is generally a bug. Anyone wanting to do this can suppress their compiler's warning by explicitly `static_cast`ing the lock holder to void.

Reviewed By: vitaut

Differential Revision: D15504563

fbshipit-source-id: 1033f6a1d4044b9698934b73eefebfe83602a2a5
parent 670c29f0
......@@ -278,9 +278,9 @@ class SharedMutexImpl {
typedef SharedMutexToken Token;
class ReadHolder;
class UpgradeHolder;
class WriteHolder;
class FOLLY_NODISCARD ReadHolder;
class FOLLY_NODISCARD UpgradeHolder;
class FOLLY_NODISCARD WriteHolder;
constexpr SharedMutexImpl() noexcept : state_(0) {}
......@@ -1301,7 +1301,7 @@ class SharedMutexImpl {
}
public:
class ReadHolder {
class FOLLY_NODISCARD ReadHolder {
ReadHolder() : lock_(nullptr) {}
public:
......@@ -1363,7 +1363,7 @@ class SharedMutexImpl {
SharedMutexToken token_;
};
class UpgradeHolder {
class FOLLY_NODISCARD UpgradeHolder {
UpgradeHolder() : lock_(nullptr) {}
public:
......@@ -1413,7 +1413,7 @@ class SharedMutexImpl {
SharedMutexImpl* lock_;
};
class WriteHolder {
class FOLLY_NODISCARD WriteHolder {
WriteHolder() : lock_(nullptr) {}
public:
......
......@@ -16,6 +16,7 @@
#pragma once
#include <folly/IntrusiveList.h>
#include <folly/Portability.h>
#include <folly/SpinLock.h>
#include <folly/fibers/GenericBaton.h>
......@@ -149,7 +150,7 @@ class TimedRWMutexImpl {
// are any.
void downgrade();
class ReadHolder {
class FOLLY_NODISCARD ReadHolder {
public:
explicit ReadHolder(TimedRWMutexImpl& lock) : lock_(&lock) {
lock_->read_lock();
......@@ -170,7 +171,7 @@ class TimedRWMutexImpl {
TimedRWMutexImpl* lock_;
};
class WriteHolder {
class FOLLY_NODISCARD WriteHolder {
public:
explicit WriteHolder(TimedRWMutexImpl& lock) : lock_(&lock) {
lock_->write_lock();
......
......@@ -17,6 +17,7 @@
#pragma once
#include <assert.h>
#include <folly/Portability.h>
#include <cstddef>
#include <cstdint>
#include <functional>
......@@ -59,7 +60,7 @@ class DelayedDestructionBase {
* object, causing problems when the callback function returns and the
* guarded object's method resumes execution.
*/
class DestructorGuard {
class FOLLY_NODISCARD DestructorGuard {
public:
explicit DestructorGuard(DelayedDestructionBase* dd) : dd_(dd) {
if (dd_ != nullptr) {
......
......@@ -307,11 +307,11 @@ class RWSpinLock {
return bits_.load(std::memory_order_acquire);
}
class ReadHolder;
class UpgradedHolder;
class WriteHolder;
class FOLLY_NODISCARD ReadHolder;
class FOLLY_NODISCARD UpgradedHolder;
class FOLLY_NODISCARD WriteHolder;
class ReadHolder {
class FOLLY_NODISCARD ReadHolder {
public:
explicit ReadHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) {
......@@ -380,7 +380,7 @@ class RWSpinLock {
RWSpinLock* lock_;
};
class UpgradedHolder {
class FOLLY_NODISCARD UpgradedHolder {
public:
explicit UpgradedHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) {
......@@ -443,7 +443,7 @@ class RWSpinLock {
RWSpinLock* lock_;
};
class WriteHolder {
class FOLLY_NODISCARD WriteHolder {
public:
explicit WriteHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) {
......@@ -742,10 +742,10 @@ class RWTicketSpinLockT {
__sync_fetch_and_add(&ticket.write, 1);
}
class WriteHolder;
class FOLLY_NODISCARD WriteHolder;
typedef RWTicketSpinLockT<kBitWidth, kFavorWriter> RWSpinLock;
class ReadHolder {
class FOLLY_NODISCARD ReadHolder {
public:
ReadHolder(ReadHolder const&) = delete;
ReadHolder& operator=(ReadHolder const&) = delete;
......@@ -794,7 +794,7 @@ class RWTicketSpinLockT {
RWSpinLock* lock_;
};
class WriteHolder {
class FOLLY_NODISCARD WriteHolder {
public:
WriteHolder(WriteHolder const&) = delete;
WriteHolder& operator=(WriteHolder const&) = delete;
......
......@@ -16,6 +16,7 @@
#pragma once
#include <folly/Portability.h>
#include <mutex>
namespace folly {
......@@ -39,7 +40,9 @@ namespace folly {
* of std::unique_lock
*/
template <typename Mutex, typename... Args>
std::unique_lock<Mutex> make_unique_lock(Mutex& mutex, Args&&... args) {
FOLLY_NODISCARD std::unique_lock<Mutex> make_unique_lock(
Mutex& mutex,
Args&&... args) {
return std::unique_lock<Mutex>{mutex, std::forward<Args>(args)...};
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment