Commit 51196c8d authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

clang-format in preparation for changes

Reviewed By: shixiao

Differential Revision: D8333485

fbshipit-source-id: 02f74700272b663474c2f02535265ffb6f4bcd22
parent 9d6a5522
...@@ -256,8 +256,8 @@ class SharedMutexImpl { ...@@ -256,8 +256,8 @@ class SharedMutexImpl {
SharedMutexImpl(const SharedMutexImpl&) = delete; SharedMutexImpl(const SharedMutexImpl&) = delete;
SharedMutexImpl(SharedMutexImpl&&) = delete; SharedMutexImpl(SharedMutexImpl&&) = delete;
SharedMutexImpl& operator = (const SharedMutexImpl&) = delete; SharedMutexImpl& operator=(const SharedMutexImpl&) = delete;
SharedMutexImpl& operator = (SharedMutexImpl&&) = delete; SharedMutexImpl& operator=(SharedMutexImpl&&) = delete;
// It is an error to destroy an SharedMutex that still has // It is an error to destroy an SharedMutex that still has
// any outstanding locks. This is checked if NDEBUG isn't defined. // any outstanding locks. This is checked if NDEBUG isn't defined.
...@@ -352,7 +352,8 @@ class SharedMutexImpl { ...@@ -352,7 +352,8 @@ class SharedMutexImpl {
} }
template <class Rep, class Period> template <class Rep, class Period>
bool try_lock_shared_for(const std::chrono::duration<Rep, Period>& duration, bool try_lock_shared_for(
const std::chrono::duration<Rep, Period>& duration,
Token& token) { Token& token) {
WaitForDuration<Rep, Period> ctx(duration); WaitForDuration<Rep, Period> ctx(duration);
return lockSharedImpl(&token, ctx); return lockSharedImpl(&token, ctx);
...@@ -391,7 +392,8 @@ class SharedMutexImpl { ...@@ -391,7 +392,8 @@ class SharedMutexImpl {
} }
void unlock_shared(Token& token) { void unlock_shared(Token& token) {
assert(token.type_ == Token::Type::INLINE_SHARED || assert(
token.type_ == Token::Type::INLINE_SHARED ||
token.type_ == Token::Type::DEFERRED_SHARED); token.type_ == Token::Type::DEFERRED_SHARED);
if (token.type_ != Token::Type::DEFERRED_SHARED || if (token.type_ != Token::Type::DEFERRED_SHARED ||
...@@ -500,9 +502,15 @@ class SharedMutexImpl { ...@@ -500,9 +502,15 @@ class SharedMutexImpl {
// before the wait context is invoked. // before the wait context is invoked.
struct WaitForever { struct WaitForever {
bool canBlock() { return true; } bool canBlock() {
bool canTimeOut() { return false; } return true;
bool shouldTimeOut() { return false; } }
bool canTimeOut() {
return false;
}
bool shouldTimeOut() {
return false;
}
bool doWait(Futex& futex, uint32_t expected, uint32_t waitMask) { bool doWait(Futex& futex, uint32_t expected, uint32_t waitMask) {
futex.futexWait(expected, waitMask); futex.futexWait(expected, waitMask);
...@@ -511,11 +519,18 @@ class SharedMutexImpl { ...@@ -511,11 +519,18 @@ class SharedMutexImpl {
}; };
struct WaitNever { struct WaitNever {
bool canBlock() { return false; } bool canBlock() {
bool canTimeOut() { return true; } return false;
bool shouldTimeOut() { return true; } }
bool canTimeOut() {
return true;
}
bool shouldTimeOut() {
return true;
}
bool doWait(Futex& /* futex */, bool doWait(
Futex& /* futex */,
uint32_t /* expected */, uint32_t /* expected */,
uint32_t /* waitMask */) { uint32_t /* waitMask */) {
return false; return false;
...@@ -539,8 +554,12 @@ class SharedMutexImpl { ...@@ -539,8 +554,12 @@ class SharedMutexImpl {
return deadline_; return deadline_;
} }
bool canBlock() { return duration_.count() > 0; } bool canBlock() {
bool canTimeOut() { return true; } return duration_.count() > 0;
}
bool canTimeOut() {
return true;
}
bool shouldTimeOut() { bool shouldTimeOut() {
return std::chrono::steady_clock::now() > deadline(); return std::chrono::steady_clock::now() > deadline();
...@@ -556,9 +575,15 @@ class SharedMutexImpl { ...@@ -556,9 +575,15 @@ class SharedMutexImpl {
struct WaitUntilDeadline { struct WaitUntilDeadline {
std::chrono::time_point<Clock, Duration> absDeadline_; std::chrono::time_point<Clock, Duration> absDeadline_;
bool canBlock() { return true; } bool canBlock() {
bool canTimeOut() { return true; } return true;
bool shouldTimeOut() { return Clock::now() > absDeadline_; } }
bool canTimeOut() {
return true;
}
bool shouldTimeOut() {
return Clock::now() > absDeadline_;
}
bool doWait(Futex& futex, uint32_t expected, uint32_t waitMask) { bool doWait(Futex& futex, uint32_t expected, uint32_t waitMask) {
auto result = futex.futexWaitUntil(expected, absDeadline_, waitMask); auto result = futex.futexWaitUntil(expected, absDeadline_, waitMask);
...@@ -703,10 +728,11 @@ class SharedMutexImpl { ...@@ -703,10 +728,11 @@ class SharedMutexImpl {
static constexpr uint32_t kDeferredSeparationFactor = 4; static constexpr uint32_t kDeferredSeparationFactor = 4;
private: private:
static_assert(
static_assert(!(kMaxDeferredReaders & (kMaxDeferredReaders - 1)), !(kMaxDeferredReaders & (kMaxDeferredReaders - 1)),
"kMaxDeferredReaders must be a power of 2"); "kMaxDeferredReaders must be a power of 2");
static_assert(!(kDeferredSearchDistance & (kDeferredSearchDistance - 1)), static_assert(
!(kDeferredSearchDistance & (kDeferredSearchDistance - 1)),
"kDeferredSearchDistance must be a power of 2"); "kDeferredSearchDistance must be a power of 2");
// The number of deferred locks that can be simultaneously acquired // The number of deferred locks that can be simultaneously acquired
...@@ -733,7 +759,6 @@ class SharedMutexImpl { ...@@ -733,7 +759,6 @@ class SharedMutexImpl {
// Last deferred reader slot used. // Last deferred reader slot used.
static FOLLY_SHAREDMUTEX_TLS uint32_t tls_lastDeferredReaderSlot; static FOLLY_SHAREDMUTEX_TLS uint32_t tls_lastDeferredReaderSlot;
// Only indexes divisible by kDeferredSeparationFactor are used. // Only indexes divisible by kDeferredSeparationFactor are used.
// If any of those elements points to a SharedMutexImpl, then it // If any of those elements points to a SharedMutexImpl, then it
// should be considered that there is a shared lock on that instance. // should be considered that there is a shared lock on that instance.
...@@ -760,7 +785,8 @@ class SharedMutexImpl { ...@@ -760,7 +785,8 @@ class SharedMutexImpl {
} }
template <class WaitContext> template <class WaitContext>
bool lockExclusiveImpl(uint32_t& state, bool lockExclusiveImpl(
uint32_t& state,
uint32_t preconditionGoalMask, uint32_t preconditionGoalMask,
WaitContext& ctx) { WaitContext& ctx) {
while (true) { while (true) {
...@@ -814,8 +840,8 @@ class SharedMutexImpl { ...@@ -814,8 +840,8 @@ class SharedMutexImpl {
if (kReaderPriority && (state & kHasE) == 0) { if (kReaderPriority && (state & kHasE) == 0) {
assert((state & kBegunE) != 0); assert((state & kBegunE) != 0);
if (!state_.compare_exchange_strong(state, if (!state_.compare_exchange_strong(
(state & ~kBegunE) | kHasE)) { state, (state & ~kBegunE) | kHasE)) {
continue; continue;
} }
} }
...@@ -827,7 +853,8 @@ class SharedMutexImpl { ...@@ -827,7 +853,8 @@ class SharedMutexImpl {
} }
template <class WaitContext> template <class WaitContext>
bool waitForZeroBits(uint32_t& state, bool waitForZeroBits(
uint32_t& state,
uint32_t goal, uint32_t goal,
uint32_t waitMask, uint32_t waitMask,
WaitContext& ctx) { WaitContext& ctx) {
...@@ -847,7 +874,8 @@ class SharedMutexImpl { ...@@ -847,7 +874,8 @@ class SharedMutexImpl {
} }
template <class WaitContext> template <class WaitContext>
bool yieldWaitForZeroBits(uint32_t& state, bool yieldWaitForZeroBits(
uint32_t& state,
uint32_t goal, uint32_t goal,
uint32_t waitMask, uint32_t waitMask,
WaitContext& ctx) { WaitContext& ctx) {
...@@ -887,11 +915,13 @@ class SharedMutexImpl { ...@@ -887,11 +915,13 @@ class SharedMutexImpl {
} }
template <class WaitContext> template <class WaitContext>
bool futexWaitForZeroBits(uint32_t& state, bool futexWaitForZeroBits(
uint32_t& state,
uint32_t goal, uint32_t goal,
uint32_t waitMask, uint32_t waitMask,
WaitContext& ctx) { WaitContext& ctx) {
assert(waitMask == kWaitingNotS || waitMask == kWaitingE || assert(
waitMask == kWaitingNotS || waitMask == kWaitingE ||
waitMask == kWaitingU || waitMask == kWaitingS); waitMask == kWaitingU || waitMask == kWaitingS);
while (true) { while (true) {
...@@ -949,8 +979,7 @@ class SharedMutexImpl { ...@@ -949,8 +979,7 @@ class SharedMutexImpl {
// wakeup, we just disable the optimization in the case that there // wakeup, we just disable the optimization in the case that there
// are waiting U or S that we are eligible to wake. // are waiting U or S that we are eligible to wake.
if ((wakeMask & kWaitingE) == kWaitingE && if ((wakeMask & kWaitingE) == kWaitingE &&
(state & wakeMask) == kWaitingE && (state & wakeMask) == kWaitingE && state_.futexWake(1, kWaitingE) > 0) {
state_.futexWake(1, kWaitingE) > 0) {
// somebody woke up, so leave state_ as is and clear it later // somebody woke up, so leave state_ as is and clear it later
return; return;
} }
...@@ -972,9 +1001,13 @@ class SharedMutexImpl { ...@@ -972,9 +1001,13 @@ class SharedMutexImpl {
return &deferredReaders[slot * kDeferredSeparationFactor]; return &deferredReaders[slot * kDeferredSeparationFactor];
} }
uintptr_t tokenfulSlotValue() { return reinterpret_cast<uintptr_t>(this); } uintptr_t tokenfulSlotValue() {
return reinterpret_cast<uintptr_t>(this);
}
uintptr_t tokenlessSlotValue() { return tokenfulSlotValue() | kTokenless; } uintptr_t tokenlessSlotValue() {
return tokenfulSlotValue() | kTokenless;
}
bool slotValueIsThis(uintptr_t slotValue) { bool slotValueIsThis(uintptr_t slotValue) {
return (slotValue & ~kTokenless) == tokenfulSlotValue(); return (slotValue & ~kTokenless) == tokenfulSlotValue();
...@@ -1006,7 +1039,6 @@ class SharedMutexImpl { ...@@ -1006,7 +1039,6 @@ class SharedMutexImpl {
template <class WaitContext> template <class WaitContext>
void applyDeferredReaders(uint32_t& state, WaitContext& ctx, uint32_t slot) { void applyDeferredReaders(uint32_t& state, WaitContext& ctx, uint32_t slot) {
#ifdef RUSAGE_THREAD #ifdef RUSAGE_THREAD
struct rusage usage; struct rusage usage;
std::memset(&usage, 0, sizeof(usage)); std::memset(&usage, 0, sizeof(usage));
...@@ -1118,7 +1150,8 @@ class SharedMutexImpl { ...@@ -1118,7 +1150,8 @@ class SharedMutexImpl {
uint32_t unlockSharedInline() { uint32_t unlockSharedInline() {
uint32_t state = (state_ -= kIncrHasS); uint32_t state = (state_ -= kIncrHasS);
assert((state & (kHasE | kBegunE | kMayDefer)) != 0 || assert(
(state & (kHasE | kBegunE | kMayDefer)) != 0 ||
state < state + kIncrHasS); state < state + kIncrHasS);
if ((state & kHasS) == 0) { if ((state & kHasS) == 0) {
// Only the second half of lock() can be blocked by a non-zero // Only the second half of lock() can be blocked by a non-zero
...@@ -1156,8 +1189,8 @@ class SharedMutexImpl { ...@@ -1156,8 +1189,8 @@ class SharedMutexImpl {
lock_->lock_shared(token_); lock_->lock_shared(token_);
} }
ReadHolder(ReadHolder&& rhs) noexcept : lock_(rhs.lock_), ReadHolder(ReadHolder&& rhs) noexcept
token_(rhs.token_) { : lock_(rhs.lock_), token_(rhs.token_) {
rhs.lock_ = nullptr; rhs.lock_ = nullptr;
} }
...@@ -1327,10 +1360,18 @@ class SharedMutexImpl { ...@@ -1327,10 +1360,18 @@ class SharedMutexImpl {
}; };
// Adapters for Synchronized<> // Adapters for Synchronized<>
friend void acquireRead(SharedMutexImpl& lock) { lock.lock_shared(); } friend void acquireRead(SharedMutexImpl& lock) {
friend void acquireReadWrite(SharedMutexImpl& lock) { lock.lock(); } lock.lock_shared();
friend void releaseRead(SharedMutexImpl& lock) { lock.unlock_shared(); } }
friend void releaseReadWrite(SharedMutexImpl& lock) { lock.unlock(); } friend void acquireReadWrite(SharedMutexImpl& lock) {
lock.lock();
}
friend void releaseRead(SharedMutexImpl& lock) {
lock.unlock_shared();
}
friend void releaseReadWrite(SharedMutexImpl& lock) {
lock.unlock();
}
friend bool acquireRead(SharedMutexImpl& lock, unsigned int ms) { friend bool acquireRead(SharedMutexImpl& lock, unsigned int ms) {
return lock.try_lock_shared_for(std::chrono::milliseconds(ms)); return lock.try_lock_shared_for(std::chrono::milliseconds(ms));
} }
......
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