Let Futex import base-class ctors
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 10 Jan 2018 20:05:34 +0000 (12:05 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 10 Jan 2018 20:18:31 +0000 (12:18 -0800)
Summary:
[Folly] Let `Futex` import base-class ctors.

Rather than needing to define ctors and inherit `boost::noncopyable`.

Reviewed By: WillerZ

Differential Revision: D6674054

fbshipit-source-id: 59e0a4815682b227346954fe47c6eda49e3ad62f

folly/SharedMutex.h
folly/SpinLock.h
folly/concurrency/DynamicBoundedQueue.h
folly/detail/Futex.h
folly/experimental/FlatCombiningPriorityQueue.h
folly/fibers/Baton.h
folly/synchronization/detail/ThreadCachedInts.h

index ce160f8087a99a1d7bdfab51fc5e2c040d3a6dbc..976c6e09f80f9918aa1f599167aea16a00ab6f52 100644 (file)
@@ -563,7 +563,7 @@ class SharedMutexImpl {
   };
 
   // 32 bits of state
-  Futex state_;
+  Futex state_{};
 
   // S count needs to be on the end, because we explicitly allow it to
   // underflow.  This can occur while we are in the middle of applying
index 3df5d4e1c6a10b99f0bb269a937c0bd4fa7cb8af..a735fcd17d60382833ab7d4103303b63b282ab42 100644 (file)
@@ -34,6 +34,8 @@
 
 #include <type_traits>
 
+#include <boost/noncopyable.hpp>
+
 #include <folly/Portability.h>
 #include <folly/SmallLocks.h>
 
index e6634b8df8e494fee7eea6f9755c6880abcea29c..18ff4928935627bdc64b28fd5bacfc68a7841a59 100644 (file)
@@ -330,7 +330,8 @@ class DynamicBoundedQueue {
         capacity_(capacity + threshold(capacity)), // capacity slack
         credit_(0),
         threshold_(threshold(capacity)),
-        transfer_(0) {}
+        transfer_(0),
+        waiting_(0) {}
 
   /** destructor */
   ~DynamicBoundedQueue() {}
index 630ad6963927f2433ae98a6c9e67daacdf75b11e..de0c78f9bef0438c006af86eecf90a84477c40e9 100644 (file)
@@ -22,8 +22,6 @@
 #include <limits>
 #include <type_traits>
 
-#include <boost/noncopyable.hpp>
-
 #include <folly/portability/Unistd.h>
 
 namespace folly { namespace detail {
@@ -45,9 +43,8 @@ enum class FutexResult {
  * (and benchmarks to back you up).
  */
 template <template <typename> class Atom = std::atomic>
-struct Futex : Atom<uint32_t>, boost::noncopyable {
-
-  explicit constexpr Futex(uint32_t init = 0) : Atom<uint32_t>(init) {}
+struct Futex : Atom<uint32_t> {
+  using Atom<uint32_t>::Atom;
 
   /** Puts the thread to sleep if this->load() == expected.  Returns true when
    *  it is returning because it has consumed a wake() event, false for any
index a8c3c1288079873ea59c61c8f9d9828404decf88..5e57e313219cf1039605809f901f365b81fd8869 100644 (file)
@@ -171,8 +171,8 @@ class FlatCombiningPriorityQueue
  private:
   size_t maxSize_;
   PriorityQueue pq_;
-  detail::Futex<Atom> empty_;
-  detail::Futex<Atom> full_;
+  detail::Futex<Atom> empty_{};
+  detail::Futex<Atom> full_{};
 
   bool isTrue(detail::Futex<Atom>& futex) {
     return futex.load(std::memory_order_relaxed) != 0;
index 286ded79299cfcc090c06c178236ffc40b1e1f76..65694b6677dada8bd5cfb65fb400a1b6ea01e8ea 100644 (file)
@@ -258,7 +258,7 @@ class Baton {
   union {
     std::atomic<intptr_t> waitingFiber_;
     struct {
-      folly::detail::Futex<> futex;
+      folly::detail::Futex<> futex{};
       int32_t _unused_packing;
     } futex_;
   };
index 1e6b0fb8f077e6e3afe8a42e8ea085782a15af94..1363cc1a31250586175801bb1404d6afb9f1078f 100644 (file)
@@ -38,7 +38,7 @@ template <typename Tag>
 class ThreadCachedInts {
   std::atomic<int64_t> orphan_inc_[2];
   std::atomic<int64_t> orphan_dec_[2];
-  folly::detail::Futex<> waiting_;
+  folly::detail::Futex<> waiting_{0};
 
   class Integer {
    public: