template <typename WaitFunc>
TimedMutex::LockResult TimedMutex::lockHelper(WaitFunc&& waitFunc) {
- std::unique_lock<folly::SpinLock> lock(lock_);
+ std::unique_lock<folly::SpinLock> ulock(lock_);
if (!locked_) {
locked_ = true;
return LockResult::SUCCESS;
threadWaiters_.push_back(waiter);
}
- lock.unlock();
+ ulock.unlock();
if (!waitFunc(waiter)) {
return LockResult::TIMEOUT;
template <typename BatonType>
void TimedRWMutex<BatonType>::read_lock() {
- std::unique_lock<folly::SpinLock> lock{lock_};
+ std::unique_lock<folly::SpinLock> ulock{lock_};
if (state_ == State::WRITE_LOCKED) {
MutexWaiter waiter;
read_waiters_.push_back(waiter);
- lock.unlock();
+ ulock.unlock();
waiter.baton.wait();
assert(state_ == State::READ_LOCKED);
return;
template <typename Rep, typename Period>
bool TimedRWMutex<BatonType>::timed_read_lock(
const std::chrono::duration<Rep, Period>& duration) {
- std::unique_lock<folly::SpinLock> lock{lock_};
+ std::unique_lock<folly::SpinLock> ulock{lock_};
if (state_ == State::WRITE_LOCKED) {
MutexWaiter waiter;
read_waiters_.push_back(waiter);
- lock.unlock();
+ ulock.unlock();
if (!waiter.baton.timed_wait(duration)) {
// We timed out. Two cases:
template <typename BatonType>
void TimedRWMutex<BatonType>::write_lock() {
- std::unique_lock<folly::SpinLock> lock{lock_};
+ std::unique_lock<folly::SpinLock> ulock{lock_};
if (state_ == State::UNLOCKED) {
verify_unlocked_properties();
state_ = State::WRITE_LOCKED;
}
MutexWaiter waiter;
write_waiters_.push_back(waiter);
- lock.unlock();
+ ulock.unlock();
waiter.baton.wait();
}
template <typename Rep, typename Period>
bool TimedRWMutex<BatonType>::timed_write_lock(
const std::chrono::duration<Rep, Period>& duration) {
- std::unique_lock<folly::SpinLock> lock{lock_};
+ std::unique_lock<folly::SpinLock> ulock{lock_};
if (state_ == State::UNLOCKED) {
verify_unlocked_properties();
state_ = State::WRITE_LOCKED;
}
MutexWaiter waiter;
write_waiters_.push_back(waiter);
- lock.unlock();
+ ulock.unlock();
if (!waiter.baton.timed_wait(duration)) {
// We timed out. Two cases: