Skip to content

Commit 35cced8

Browse files
yfeldblumfacebook-github-bot
authored andcommitted
mark nested-name lock-holder types as deprecated
Summary: The nested-name lock-holder types `{mutex}::ReadHolder`, `{mutex}::WriteHolder`, and `{mutex}::UpgradeHolder` are deprecated in favor of the canonical lock-holder types `std::shared_lock`, `std::unique_lock`, and `folly::upgrade_lock` respectively. Reviewed By: ot, malanka, dmm-fb Differential Revision: D52371884 fbshipit-source-id: 2b4b87d082f9f689f7c03b01595b81b7ba935e3c
1 parent 99c8e62 commit 35cced8

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

folly/Portability.h

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ constexpr bool kHasUnalignedAccess = false;
8686
#define FOLLY_NODISCARD
8787
#endif
8888

89+
// older clang-format gets confused by [[deprecated(...)]] on class decls
90+
#define FOLLY_DEPRECATED(...) [[deprecated(__VA_ARGS__)]]
91+
8992
// target
9093
#ifdef _MSC_VER
9194
#define FOLLY_TARGET_ATTRIBUTE(target)

folly/SharedMutex.h

+5-11
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@
101101
// is held. See https://github.com/boostorg/thread/blob/master/
102102
// include/boost/thread/pthread/shared_mutex.hpp
103103
//
104-
// * RWSpinLock::UpgradedHolder maps to SharedMutex::UpgradeHolder
105-
// (UpgradeableHolder would be even more pedantically correct).
106-
// SharedMutex's holders have fewer methods (no reset) and are less
107-
// tolerant (promotion and downgrade crash if the donor doesn't own
108-
// the lock, and you must use the default constructor rather than
109-
// passing a nullptr to the pointer constructor).
110-
//
111104
// Both SharedMutex and RWSpinLock provide "exclusive", "upgrade",
112105
// and "shared" modes. At all times num_threads_holding_exclusive +
113106
// num_threads_holding_upgrade <= 1, and num_threads_holding_exclusive ==
@@ -193,7 +186,7 @@
193186
// recorded the lock, which might be in the lock itself or in any of
194187
// the shared slots. If you can conveniently pass state from lock
195188
// acquisition to release then the fastest mechanism is to std::move
196-
// the SharedMutex::ReadHolder instance or an SharedMutex::Token (using
189+
// the std::shared_lock instance or an SharedMutex::Token (using
197190
// lock_shared(Token&) and unlock_shared(Token&)). The guard or token
198191
// will tell unlock_shared where in deferredReaders[] to look for the
199192
// deferred lock. The Token-less version of unlock_shared() works in all
@@ -1433,7 +1426,7 @@ class SharedMutexImpl : std::conditional_t<
14331426
}
14341427

14351428
public:
1436-
class FOLLY_NODISCARD ReadHolder {
1429+
class FOLLY_NODISCARD FOLLY_DEPRECATED("use std::shared_lock") ReadHolder {
14371430
using folly_is_unsafe_for_async_usage = std::true_type;
14381431

14391432
ReadHolder() : lock_(nullptr) {}
@@ -1495,7 +1488,8 @@ class SharedMutexImpl : std::conditional_t<
14951488
SharedMutexToken token_;
14961489
};
14971490

1498-
class FOLLY_NODISCARD UpgradeHolder {
1491+
class FOLLY_NODISCARD FOLLY_DEPRECATED("use folly::upgrade_lock")
1492+
UpgradeHolder {
14991493
using folly_is_unsafe_for_async_usage = std::true_type;
15001494

15011495
UpgradeHolder() : lock_(nullptr) {}
@@ -1545,7 +1539,7 @@ class SharedMutexImpl : std::conditional_t<
15451539
SharedMutexImpl* lock_;
15461540
};
15471541

1548-
class FOLLY_NODISCARD WriteHolder {
1542+
class FOLLY_NODISCARD FOLLY_DEPRECATED("use std::unique_lock") WriteHolder {
15491543
using folly_is_unsafe_for_async_usage = std::true_type;
15501544

15511545
WriteHolder() : lock_(nullptr) {}

folly/fibers/TimedMutex.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class TimedRWMutexImpl {
178178
// are any.
179179
void unlock_and_lock_shared();
180180

181-
class FOLLY_NODISCARD ReadHolder {
181+
class FOLLY_NODISCARD FOLLY_DEPRECATED("use std::shared_lock") ReadHolder {
182182
public:
183183
explicit ReadHolder(TimedRWMutexImpl& lock) : lock_(&lock) {
184184
lock_->lock_shared();
@@ -199,7 +199,7 @@ class TimedRWMutexImpl {
199199
TimedRWMutexImpl* lock_;
200200
};
201201

202-
class FOLLY_NODISCARD WriteHolder {
202+
class FOLLY_NODISCARD FOLLY_DEPRECATED("use std::unique_lock") WriteHolder {
203203
public:
204204
explicit WriteHolder(TimedRWMutexImpl& lock) : lock_(&lock) {
205205
lock_->lock();

folly/synchronization/RWSpinLock.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class RWSpinLock {
309309
class FOLLY_NODISCARD UpgradedHolder;
310310
class FOLLY_NODISCARD WriteHolder;
311311

312-
class FOLLY_NODISCARD ReadHolder {
312+
class FOLLY_NODISCARD FOLLY_DEPRECATED("use std::shared_lock") ReadHolder {
313313
public:
314314
explicit ReadHolder(RWSpinLock* lock) : lock_(lock) {
315315
if (lock_) {
@@ -376,7 +376,8 @@ class RWSpinLock {
376376
RWSpinLock* lock_;
377377
};
378378

379-
class FOLLY_NODISCARD UpgradedHolder {
379+
class FOLLY_NODISCARD FOLLY_DEPRECATED("use folly::upgrade_lock")
380+
UpgradedHolder {
380381
public:
381382
explicit UpgradedHolder(RWSpinLock* lock) : lock_(lock) {
382383
if (lock_) {
@@ -439,7 +440,7 @@ class RWSpinLock {
439440
RWSpinLock* lock_;
440441
};
441442

442-
class FOLLY_NODISCARD WriteHolder {
443+
class FOLLY_NODISCARD FOLLY_DEPRECATED("use std::unique_lock") WriteHolder {
443444
public:
444445
explicit WriteHolder(RWSpinLock* lock) : lock_(lock) {
445446
if (lock_) {

0 commit comments

Comments
 (0)