Remove the old SpinLock implementations
authorChristopher Dykes <cdykes@fb.com>
Fri, 14 Apr 2017 18:14:45 +0000 (11:14 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 14 Apr 2017 18:28:26 +0000 (11:28 -0700)
Summary: They aren't actually needed as the primary implementation is supported on all platforms.

Reviewed By: yfeldblum

Differential Revision: D4882687

fbshipit-source-id: 7208c5d3c1f35b29b0cabb6a20fe030fbf10b131

folly/Makefile.am
folly/SpinLock.h
folly/detail/SpinLockImpl.h [deleted file]
folly/io/async/NotificationQueue.h
folly/test/SpinLockTest.cpp

index 0e6467b2e1221a111f960e79a3b7848b0e644500..b2dbcfaf45f029db312b834a643bbcc1f58d49b2 100644 (file)
@@ -76,7 +76,6 @@ nobase_follyinclude_HEADERS = \
        detail/Sleeper.h \
        detail/SlowFingerprint.h \
        detail/SocketFastOpen.h \
        detail/Sleeper.h \
        detail/SlowFingerprint.h \
        detail/SocketFastOpen.h \
-       detail/SpinLockImpl.h \
        detail/StaticSingletonManager.h \
        detail/Stats.h \
        detail/ThreadLocalDetail.h \
        detail/StaticSingletonManager.h \
        detail/Stats.h \
        detail/ThreadLocalDetail.h \
index ef35a48578aae405d838628f306270bfd22a7688..b87e58a6ed074415bd230dd21157f06dbb74078e 100644 (file)
 
 #include <type_traits>
 
 
 #include <type_traits>
 
-#include <folly/detail/SpinLockImpl.h>
+#include <folly/Portability.h>
+#include <folly/SmallLocks.h>
 
 namespace folly {
 
 
 namespace folly {
 
-#if __x86_64__
-typedef SpinLockMslImpl SpinLock;
-#elif __APPLE__
-typedef SpinLockAppleImpl SpinLock;
-#elif FOLLY_HAVE_PTHREAD_SPINLOCK_T
-typedef SpinLockPthreadImpl SpinLock;
-#else
-typedef SpinLockPthreadMutexImpl SpinLock;
-#endif
+class SpinLock {
+ public:
+  FOLLY_ALWAYS_INLINE SpinLock() {
+    lock_.init();
+  }
+  FOLLY_ALWAYS_INLINE void lock() const {
+    lock_.lock();
+  }
+  FOLLY_ALWAYS_INLINE void unlock() const {
+    lock_.unlock();
+  }
+  FOLLY_ALWAYS_INLINE bool try_lock() const {
+    return lock_.try_lock();
+  }
+
+ private:
+  mutable folly::MicroSpinLock lock_;
+};
 
 template <typename LOCK>
 class SpinLockGuardImpl : private boost::noncopyable {
 
 template <typename LOCK>
 class SpinLockGuardImpl : private boost::noncopyable {
diff --git a/folly/detail/SpinLockImpl.h b/folly/detail/SpinLockImpl.h
deleted file mode 100644 (file)
index 22ba753..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright 2017 Facebook, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-/*
- * This class provides a few spin lock implementations, depending on the
- * platform.  folly/SpinLock.h will select one of these as the folly::SpinLock
- * implementation.
- *
- * The main reason we keep these separated out here is so that we can run unit
- * tests for all supported spin lock implementations, even though only one will
- * be selected as the actual folly::SpinLock implemenatation for any given
- * platform.
- */
-
-#include <boost/noncopyable.hpp>
-#include <folly/Portability.h>
-
-#if __x86_64__
-#include <folly/SmallLocks.h>
-
-namespace folly {
-
-class SpinLockMslImpl {
- public:
-  FOLLY_ALWAYS_INLINE SpinLockMslImpl() {
-    lock_.init();
-  }
-  FOLLY_ALWAYS_INLINE void lock() const {
-    lock_.lock();
-  }
-  FOLLY_ALWAYS_INLINE void unlock() const {
-    lock_.unlock();
-  }
-  FOLLY_ALWAYS_INLINE bool try_lock() const {
-    return lock_.try_lock();
-  }
- private:
-  mutable folly::MicroSpinLock lock_;
-};
-
-}
-
-#endif // __x86_64__
-
-#if __APPLE__
-#include <libkern/OSAtomic.h>
-
-namespace folly {
-
-class SpinLockAppleImpl {
- public:
-  FOLLY_ALWAYS_INLINE SpinLockAppleImpl() : lock_(0) {}
-  FOLLY_ALWAYS_INLINE void lock() const {
-    OSSpinLockLock(&lock_);
-  }
-  FOLLY_ALWAYS_INLINE void unlock() const {
-    OSSpinLockUnlock(&lock_);
-  }
-  FOLLY_ALWAYS_INLINE bool try_lock() const {
-    return OSSpinLockTry(&lock_);
-  }
- private:
-  mutable OSSpinLock lock_;
-};
-
-}
-
-#endif // __APPLE__
-
-#include <pthread.h>
-#include <folly/Exception.h>
-
-#if FOLLY_HAVE_PTHREAD_SPINLOCK_T
-
-// Apple and Android systems don't have pthread_spinlock_t, so we can't support
-// this version on those platforms.
-namespace folly {
-
-class SpinLockPthreadImpl {
- public:
-  FOLLY_ALWAYS_INLINE SpinLockPthreadImpl() {
-    int rc = pthread_spin_init(&lock_, PTHREAD_PROCESS_PRIVATE);
-    checkPosixError(rc, "failed to initialize spinlock");
-  }
-  FOLLY_ALWAYS_INLINE ~SpinLockPthreadImpl() {
-    pthread_spin_destroy(&lock_);
-  }
-  void lock() const {
-    int rc = pthread_spin_lock(&lock_);
-    checkPosixError(rc, "error locking spinlock");
-  }
-  FOLLY_ALWAYS_INLINE void unlock() const {
-    int rc = pthread_spin_unlock(&lock_);
-    checkPosixError(rc, "error unlocking spinlock");
-  }
-  FOLLY_ALWAYS_INLINE bool try_lock() const {
-    int rc = pthread_spin_trylock(&lock_);
-    if (rc == 0) {
-      return true;
-    } else if (rc == EBUSY) {
-      return false;
-    }
-    throwSystemErrorExplicit(rc, "spinlock trylock error");
-  }
- private:
-  mutable pthread_spinlock_t lock_;
-};
-
-}
-
-#endif // FOLLY_HAVE_PTHREAD_SPINLOCK_T
-
-namespace folly {
-
-class SpinLockPthreadMutexImpl {
- public:
-  FOLLY_ALWAYS_INLINE SpinLockPthreadMutexImpl() {
-    int rc = pthread_mutex_init(&lock_, nullptr);
-    checkPosixError(rc, "failed to initialize mutex");
-  }
-  FOLLY_ALWAYS_INLINE ~SpinLockPthreadMutexImpl() {
-    pthread_mutex_destroy(&lock_);
-  }
-  void lock() const {
-    int rc = pthread_mutex_lock(&lock_);
-    checkPosixError(rc, "error locking mutex");
-  }
-  FOLLY_ALWAYS_INLINE void unlock() const {
-    int rc = pthread_mutex_unlock(&lock_);
-    checkPosixError(rc, "error unlocking mutex");
-  }
-  FOLLY_ALWAYS_INLINE bool try_lock() const {
-    int rc = pthread_mutex_trylock(&lock_);
-    if (rc == 0) {
-      return true;
-    } else if (rc == EBUSY) {
-      return false;
-    }
-    throwSystemErrorExplicit(rc, "mutex trylock error");
-  }
- private:
-  mutable pthread_mutex_t lock_;
-};
-
-}
index 28a2878eb81ecde122f68b5e440d870bdb0859bc..3018a5d93662678977a02ee53fc52c2bacc706bc 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdexcept>
 #include <utility>
 
 #include <stdexcept>
 #include <utility>
 
+#include <folly/Exception.h>
 #include <folly/FileUtil.h>
 #include <folly/io/async/EventBase.h>
 #include <folly/io/async/EventHandler.h>
 #include <folly/FileUtil.h>
 #include <folly/io/async/EventBase.h>
 #include <folly/io/async/EventHandler.h>
index 029e6625bd466c1e398f48897c37fe03b3df69e3..b2387ea7b966e04998acf11b76c376a5c08ce686 100644 (file)
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 #include <folly/SpinLock.h>
 
 #include <folly/Random.h>
 #include <folly/SpinLock.h>
 
 #include <folly/Random.h>
@@ -132,36 +133,9 @@ void trylockTest() {
 
 } // unnamed namespace
 
 
 } // unnamed namespace
 
-#if __x86_64__
-TEST(SpinLock, MslCorrectness) {
-  correctnessTest<folly::SpinLockMslImpl>();
-}
-TEST(SpinLock, MslTryLock) {
-  trylockTest<folly::SpinLockMslImpl>();
-}
-#endif
-
-#if __APPLE__
-TEST(SpinLock, AppleCorrectness) {
-  correctnessTest<folly::SpinLockAppleImpl>();
-}
-TEST(SpinLock, AppleTryLock) {
-  trylockTest<folly::SpinLockAppleImpl>();
-}
-#endif
-
-#if FOLLY_HAVE_PTHREAD_SPINLOCK_T
-TEST(SpinLock, PthreadCorrectness) {
-  correctnessTest<folly::SpinLockPthreadImpl>();
-}
-TEST(SpinLock, PthreadTryLock) {
-  trylockTest<folly::SpinLockPthreadImpl>();
-}
-#endif
-
-TEST(SpinLock, MutexCorrectness) {
-  correctnessTest<folly::SpinLockPthreadMutexImpl>();
+TEST(SpinLock, Correctness) {
+  correctnessTest<folly::SpinLock>();
 }
 }
-TEST(SpinLock, MutexTryLock) {
-  trylockTest<folly::SpinLockPthreadMutexImpl>();
+TEST(SpinLock, TryLock) {
+  trylockTest<folly::SpinLock>();
 }
 }