NULL -> nullptr
[folly.git] / folly / ThreadLocal.h
index 0663417f1f7fe0d7f46e54f299fa09284216cd0c..4ecc757ad440dc983c6842a010e905395d31bdcd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include "folly/Likely.h"
 #include <type_traits>
 
-// Use noexcept on gcc 4.6 or higher
-#undef FOLLY_NOEXCEPT
-#ifdef __GNUC__
-# ifdef HAVE_FEATURES_H
-#  include <features.h>
-#  if __GNUC_PREREQ(4,6)
-#    define FOLLY_NOEXCEPT noexcept
-#    define FOLLY_ASSERT(x) x
-#  endif
-# endif
-#endif
-
-#ifndef FOLLY_NOEXCEPT
-#  define FOLLY_NOEXCEPT
-#  define FOLLY_ASSERT(x) /**/
-#endif
 
 namespace folly {
 enum class TLPDestructionMode {
@@ -140,6 +124,11 @@ class ThreadLocal {
  * We use a single global pthread_key_t per Tag to manage object destruction and
  * memory cleanup upon thread exit because there is a finite number of
  * pthread_key_t's available per machine.
+ *
+ * NOTE: Apple platforms don't support the same semantics for __thread that
+ *       Linux does (and it's only supported at all on i386). For these, use
+ *       pthread_setspecific()/pthread_getspecific() for the per-thread
+ *       storage.
  */
 
 template<class T, class Tag=void>
@@ -212,7 +201,7 @@ class ThreadLocalPtr {
     friend class ThreadLocalPtr<T,Tag>;
 
     threadlocal_detail::StaticMeta<Tag>& meta_;
-    boost::mutex* lock_;
+    std::mutex* lock_;
     int id_;
 
    public:
@@ -283,7 +272,7 @@ class ThreadLocalPtr {
     Accessor(const Accessor&) = delete;
     Accessor& operator=(const Accessor&) = delete;
 
-    Accessor(Accessor&& other) FOLLY_NOEXCEPT
+    Accessor(Accessor&& other) noexcept
       : meta_(other.meta_),
         lock_(other.lock_),
         id_(other.id_) {
@@ -291,7 +280,7 @@ class ThreadLocalPtr {
       other.lock_ = nullptr;
     }
 
-    Accessor& operator=(Accessor&& other) FOLLY_NOEXCEPT {
+    Accessor& operator=(Accessor&& other) noexcept {
       // Each Tag has its own unique meta, and accessors with different Tags
       // have different types.  So either *this is empty, or this and other
       // have the same tag.  But if they have the same tag, they have the same
@@ -331,8 +320,8 @@ class ThreadLocalPtr {
   // accessor allows a client to iterate through all thread local child
   // elements of this ThreadLocal instance.  Holds a global lock for each <Tag>
   Accessor accessAllThreads() const {
-    FOLLY_ASSERT(static_assert(!std::is_same<Tag, void>::value,
-                 "Must use a unique Tag to use the accessAllThreads feature"));
+    static_assert(!std::is_same<Tag, void>::value,
+                  "Must use a unique Tag to use the accessAllThreads feature");
     return Accessor(id_);
   }
 
@@ -350,8 +339,6 @@ class ThreadLocalPtr {
   int id_;  // every instantiation has a unique id
 };
 
-#undef FOLLY_NOEXCEPT
-
 }  // namespace folly
 
 #endif /* FOLLY_THREADLOCAL_H_ */