Commit 598b2103 authored by Rui Zhang's avatar Rui Zhang Committed by Facebook Github Bot

SharedMutex: use folly::kIsDebug instead of NDEBUG

Summary: This diff replaces all 2 occurrences of "NDEBUG" with "folly::kIsDebug" in folly/SharedMutex.h. Compared to NDEBUG, folly::kIsDebug has the equivalent functionally  but helps consolidate the conditional-compilation logic to a single place, namely folly/portability.

Reviewed By: shixiao

Differential Revision: D15379370

fbshipit-source-id: 58c563624e58a4fd18b0cfbe4c0b9ba879f8eea9
parent 73ffab43
...@@ -303,22 +303,24 @@ class SharedMutexImpl { ...@@ -303,22 +303,24 @@ class SharedMutexImpl {
cleanupTokenlessSharedDeferred(state); cleanupTokenlessSharedDeferred(state);
} }
#ifndef NDEBUG if (folly::kIsDebug) {
// These asserts check that everybody has released the lock before it // These asserts check that everybody has released the lock before it
// is destroyed. If you arrive here while debugging that is likely // is destroyed. If you arrive here while debugging that is likely
// the problem. (You could also have general heap corruption.) // the problem. (You could also have general heap corruption.)
// if a futexWait fails to go to sleep because the value has been // if a futexWait fails to go to sleep because the value has been
// changed, we don't necessarily clean up the wait bits, so it is // changed, we don't necessarily clean up the wait bits, so it is
// possible they will be set here in a correct system // possible they will be set here in a correct system
assert((state & ~(kWaitingAny | kMayDefer | kAnnotationCreated)) == 0); assert((state & ~(kWaitingAny | kMayDefer | kAnnotationCreated)) == 0);
if ((state & kMayDefer) != 0) { if ((state & kMayDefer) != 0) {
for (uint32_t slot = 0; slot < kMaxDeferredReaders; ++slot) { for (uint32_t slot = 0; slot < kMaxDeferredReaders; ++slot) {
auto slotValue = deferredReader(slot)->load(std::memory_order_relaxed); auto slotValue =
assert(!slotValueIsThis(slotValue)); deferredReader(slot)->load(std::memory_order_relaxed);
assert(!slotValueIsThis(slotValue));
(void)slotValue;
}
} }
} }
#endif
annotateDestroy(); annotateDestroy();
} }
...@@ -457,9 +459,9 @@ class SharedMutexImpl { ...@@ -457,9 +459,9 @@ class SharedMutexImpl {
!tryUnlockSharedDeferred(token.slot_)) { !tryUnlockSharedDeferred(token.slot_)) {
unlockSharedInline(); unlockSharedInline();
} }
#ifndef NDEBUG if (folly::kIsDebug) {
token.type_ = Token::Type::INVALID; token.type_ = Token::Type::INVALID;
#endif }
} }
void unlock_and_lock_shared() { void unlock_and_lock_shared() {
......
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