From cfb40f4e3e706cdc6467e9a123fc8001f14ef4c0 Mon Sep 17 00:00:00 2001 From: Maged Michael Date: Tue, 28 Mar 2017 08:36:31 -0700 Subject: [PATCH] Change trylock() to try_lock() in folly::SpinLock to conform to standard Lockable. Reviewed By: yfeldblum Differential Revision: D4782707 fbshipit-source-id: 535b42b4f2558cadc78037268d6de81a8bb49840 --- folly/detail/SpinLockImpl.h | 8 ++++---- folly/io/async/NotificationQueue.h | 2 +- folly/test/SpinLockTest.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/folly/detail/SpinLockImpl.h b/folly/detail/SpinLockImpl.h index ef974e80..22ba7535 100644 --- a/folly/detail/SpinLockImpl.h +++ b/folly/detail/SpinLockImpl.h @@ -45,7 +45,7 @@ class SpinLockMslImpl { FOLLY_ALWAYS_INLINE void unlock() const { lock_.unlock(); } - FOLLY_ALWAYS_INLINE bool trylock() const { + FOLLY_ALWAYS_INLINE bool try_lock() const { return lock_.try_lock(); } private: @@ -70,7 +70,7 @@ class SpinLockAppleImpl { FOLLY_ALWAYS_INLINE void unlock() const { OSSpinLockUnlock(&lock_); } - FOLLY_ALWAYS_INLINE bool trylock() const { + FOLLY_ALWAYS_INLINE bool try_lock() const { return OSSpinLockTry(&lock_); } private: @@ -107,7 +107,7 @@ class SpinLockPthreadImpl { int rc = pthread_spin_unlock(&lock_); checkPosixError(rc, "error unlocking spinlock"); } - FOLLY_ALWAYS_INLINE bool trylock() const { + FOLLY_ALWAYS_INLINE bool try_lock() const { int rc = pthread_spin_trylock(&lock_); if (rc == 0) { return true; @@ -143,7 +143,7 @@ class SpinLockPthreadMutexImpl { int rc = pthread_mutex_unlock(&lock_); checkPosixError(rc, "error unlocking mutex"); } - FOLLY_ALWAYS_INLINE bool trylock() const { + FOLLY_ALWAYS_INLINE bool try_lock() const { int rc = pthread_mutex_trylock(&lock_); if (rc == 0) { return true; diff --git a/folly/io/async/NotificationQueue.h b/folly/io/async/NotificationQueue.h index 28daf77a..f27b17f5 100644 --- a/folly/io/async/NotificationQueue.h +++ b/folly/io/async/NotificationQueue.h @@ -457,7 +457,7 @@ class NotificationQueue { NotificationQueue& operator=(NotificationQueue const &) = delete; inline bool checkQueueSize(size_t maxSize, bool throws=true) const { - DCHECK(0 == spinlock_.trylock()); + DCHECK(0 == spinlock_.try_lock()); if (maxSize > 0 && queue_.size() >= maxSize) { if (throws) { throw std::overflow_error("unable to add message to NotificationQueue: " diff --git a/folly/test/SpinLockTest.cpp b/folly/test/SpinLockTest.cpp index 7c263c37..029e6625 100644 --- a/folly/test/SpinLockTest.cpp +++ b/folly/test/SpinLockTest.cpp @@ -72,7 +72,7 @@ void trylockTestThread(TryLockState* state, size_t count) { break; } - bool ret = state->lock2.trylock(); + bool ret = state->lock2.try_lock(); EXPECT_NE(state->locked, ret); if (ret) { -- 2.34.1