Fix some copyright lines in folly/detail/ and folly/test/
[folly.git] / folly / detail / ThreadLocalDetail.cpp
index be0cbf60c19c43927042109f791f2ea339423fb9..667aaa98fe9d87342b1f94d219824ad10dd720ce 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * 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.
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <folly/ThreadLocal.h>
+#include <folly/detail/ThreadLocalDetail.h>
 
 #include <list>
 #include <mutex>
@@ -34,7 +34,7 @@ void StaticMetaBase::onThreadExit(void* ptr) {
 #else
   std::unique_ptr<ThreadEntry> threadEntry(static_cast<ThreadEntry*>(ptr));
 #endif
-  DCHECK_GT(threadEntry->elementsCapacity, 0);
+  DCHECK_GT(threadEntry->elementsCapacity, 0u);
   auto& meta = *threadEntry->meta;
 
   // Make sure this ThreadEntry is available if ThreadLocal A is accessed in
@@ -45,7 +45,7 @@ void StaticMetaBase::onThreadExit(void* ptr) {
   };
 
   {
-    SharedMutex::ReadHolder rlock;
+    SharedMutex::ReadHolder rlock(nullptr);
     if (meta.strict_) {
       rlock = SharedMutex::ReadHolder(meta.accessAllThreadsLock_);
     }
@@ -103,7 +103,7 @@ void StaticMetaBase::destroy(EntryID* ent) {
     std::vector<ElementWrapper> elements;
 
     {
-      SharedMutex::WriteHolder wlock;
+      SharedMutex::WriteHolder wlock(nullptr);
       if (meta.strict_) {
         /*
          * In strict mode, the logic guarantees per-thread instances are
@@ -247,79 +247,8 @@ void StaticMetaBase::reserve(EntryID* id) {
   free(reallocated);
 }
 
-namespace {
-
-struct AtForkTask {
-  folly::Function<void()> prepare;
-  folly::Function<void()> parent;
-  folly::Function<void()> child;
-};
-
-class AtForkList {
- public:
-  static AtForkList& instance() {
-    static auto instance = new AtForkList();
-    return *instance;
-  }
-
-  static void prepare() noexcept {
-    instance().tasksLock.lock();
-    auto& tasks = instance().tasks;
-    for (auto task = tasks.rbegin(); task != tasks.rend(); ++task) {
-      task->prepare();
-    }
-  }
-
-  static void parent() noexcept {
-    auto& tasks = instance().tasks;
-    for (auto& task : tasks) {
-      task.parent();
-    }
-    instance().tasksLock.unlock();
-  }
-
-  static void child() noexcept {
-    auto& tasks = instance().tasks;
-    for (auto& task : tasks) {
-      task.child();
-    }
-    instance().tasksLock.unlock();
-  }
-
-  std::mutex tasksLock;
-  std::list<AtForkTask> tasks;
-
- private:
-  AtForkList() {
-#if FOLLY_HAVE_PTHREAD_ATFORK
-    int ret = pthread_atfork(
-        &AtForkList::prepare, &AtForkList::parent, &AtForkList::child);
-    checkPosixError(ret, "pthread_atfork failed");
-#elif !__ANDROID__ && !defined(_MSC_VER)
-// pthread_atfork is not part of the Android NDK at least as of n9d. If
-// something is trying to call native fork() directly at all with Android's
-// process management model, this is probably the least of the problems.
-//
-// But otherwise, this is a problem.
-#warning pthread_atfork unavailable
-#endif
-  }
-};
-}
-
-void StaticMetaBase::initAtFork() {
-  AtForkList::instance();
-}
-
-void StaticMetaBase::registerAtFork(
-    folly::Function<void()> prepare,
-    folly::Function<void()> parent,
-    folly::Function<void()> child) {
-  std::lock_guard<std::mutex> lg(AtForkList::instance().tasksLock);
-  AtForkList::instance().tasks.push_back(
-      {std::move(prepare), std::move(parent), std::move(child)});
-}
 
 FOLLY_STATIC_CTOR_PRIORITY_MAX
 PthreadKeyUnregister PthreadKeyUnregister::instance_;
-}}
+} // namespace threadlocal_detail
+} // namespace folly