-#include <pthread.h>
-#include <glog/logging.h>
-
-namespace folly {
-
-class SpinLock {
- public:
- FOLLY_ALWAYS_INLINE SpinLock() {
- pthread_mutex_init(&lock_, nullptr);
- }
- void lock() const {
- int rc = pthread_mutex_lock(&lock_);
- CHECK_EQ(0, rc);
- }
- FOLLY_ALWAYS_INLINE void unlock() const {
- int rc = pthread_mutex_unlock(&lock_);
- CHECK_EQ(0, rc);
- }
- FOLLY_ALWAYS_INLINE bool trylock() const {
- int rc = pthread_mutex_trylock(&lock_);
- CHECK_GE(rc, 0);
- return rc == 0;
- }
- private:
- mutable pthread_mutex_t lock_;
-};
-
-}
-