Disable zerocopy if we're notified about deferred copies, add a isZeroCopyWriteInProg...
[folly.git] / folly / MicroSpinLock.h
index 5916dbdc381242842645e531f91e084e0e53b3f3..b36998a7d4a56bc8210a25e30330be4e2953bbfa 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.
@@ -16,7 +16,7 @@
 
 /*
  * N.B. You most likely do _not_ want to use MicroSpinLock or any
- * other kind of spinlock.
+ * other kind of spinlock.  Consider MicroLock instead.
  *
  * In short, spinlocks in preemptive multi-tasking operating systems
  * have serious problems and fast mutexes like std::mutex are almost
  */
 
 #include <array>
-#include <cinttypes>
-#include <type_traits>
-#include <boost/noncopyable.hpp>
-#include <cstdlib>
-#include <pthread.h>
-#include <mutex>
 #include <atomic>
+#include <cassert>
+#include <cstdint>
+#include <mutex>
+#include <type_traits>
 
-#include <glog/logging.h>
-#include <folly/detail/Sleeper.h>
 #include <folly/Portability.h>
+#include <folly/detail/Sleeper.h>
 
 namespace folly {
 
@@ -86,11 +83,11 @@ struct MicroSpinLock {
         sleeper.wait();
       }
     } while (!try_lock());
-    DCHECK(payload()->load() == LOCKED);
+    assert(payload()->load() == LOCKED);
   }
 
   void unlock() {
-    CHECK(payload()->load() == LOCKED);
+    assert(payload()->load() == LOCKED);
     payload()->store(FREE, std::memory_order_release);
   }
 
@@ -105,6 +102,9 @@ struct MicroSpinLock {
                                                         std::memory_order_relaxed);
   }
 };
+static_assert(
+    std::is_pod<MicroSpinLock>::value,
+    "MicroSpinLock must be kept a POD type.");
 
 //////////////////////////////////////////////////////////////////////
 
@@ -139,10 +139,11 @@ struct FOLLY_ALIGNED_MAX SpinLockArray {
                 "Invalid size of PaddedSpinLock");
 
   // Check if T can theoretically cross a cache line.
-  static_assert(alignof(std::max_align_t) > 0 &&
-                FOLLY_CACHE_LINE_SIZE % alignof(std::max_align_t) == 0 &&
-                sizeof(T) <= alignof(std::max_align_t),
-                "T can cross cache line boundaries");
+  static_assert(
+      folly::max_align_v > 0 &&
+          FOLLY_CACHE_LINE_SIZE % folly::max_align_v == 0 &&
+          sizeof(T) <= folly::max_align_v,
+      "T can cross cache line boundaries");
 
   char padding_[FOLLY_CACHE_LINE_SIZE];
   std::array<PaddedSpinLock, N> data_;
@@ -154,4 +155,4 @@ typedef std::lock_guard<MicroSpinLock> MSLGuard;
 
 //////////////////////////////////////////////////////////////////////
 
-}
+} // namespace folly