An intro to the upgrade mutex in the Synchronized docs
[folly.git] / folly / ConcurrentSkipList-inl.h
index c303ac0384972803e731c39a9f59df3a2e87d8da..e4144bcbfb57dfaa035ace57a2f163ac62f4dbcf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2016 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,8 +16,7 @@
 
 // @author: Xin Liu <xliux@fb.com>
 
-#ifndef FOLLY_CONCURRENTSKIPLIST_INL_H_
-#define FOLLY_CONCURRENTSKIPLIST_INL_H_
+#pragma once
 
 #include <algorithm>
 #include <atomic>
@@ -32,9 +31,9 @@
 #include <boost/type_traits.hpp>
 #include <glog/logging.h>
 
-#include "folly/Memory.h"
-#include "folly/SmallLocks.h"
-#include "folly/ThreadLocal.h"
+#include <folly/Memory.h>
+#include <folly/MicroSpinLock.h>
+#include <folly/ThreadLocal.h>
 
 namespace folly { namespace detail {
 
@@ -73,7 +72,7 @@ class SkipListNode : private boost::noncopyable {
   template<typename NodeAlloc>
   static constexpr bool destroyIsNoOp() {
     return IsArenaAllocator<NodeAlloc>::value &&
-           boost::has_trivial_destructor<std::atomic<SkipListNode*>>::value;
+           boost::has_trivial_destructor<SkipListNode>::value;
   }
 
   // copy the head node to a new head node assuming lock acquired
@@ -234,7 +233,9 @@ class NodeRecycler<NodeType, NodeAlloc, typename std::enable_if<
   !NodeType::template destroyIsNoOp<NodeAlloc>()>::type> {
  public:
   explicit NodeRecycler(const NodeAlloc& alloc)
-    : alloc_(alloc), refs_(0), dirty_(false) { lock_.init(); }
+    : refs_(0), dirty_(false), alloc_(alloc) { lock_.init(); }
+
+  explicit NodeRecycler() : refs_(0), dirty_(false) { lock_.init(); }
 
   ~NodeRecycler() {
     CHECK_EQ(refs(), 0);
@@ -304,11 +305,11 @@ class NodeRecycler<NodeType, NodeAlloc, typename std::enable_if<
     return refs_.load(std::memory_order_relaxed);
   }
 
-  NodeAlloc alloc_;
   std::unique_ptr<std::vector<NodeType*>> nodes_;
   std::atomic<int32_t> refs_; // current number of visitors to the list
   std::atomic<bool> dirty_; // whether *nodes_ is non-empty
   MicroSpinLock lock_; // protects access to *nodes_
+  NodeAlloc alloc_;
 };
 
 // In case of arena allocator, no recycling is necessary, and it's possible
@@ -322,7 +323,7 @@ class NodeRecycler<NodeType, NodeAlloc, typename std::enable_if<
   void addRef() { }
   void releaseRef() { }
 
-  void add(NodeType* node) { }
+  void add(NodeType* /* node */) {}
 
   NodeAlloc& alloc() { return alloc_; }
 
@@ -331,5 +332,3 @@ class NodeRecycler<NodeType, NodeAlloc, typename std::enable_if<
 };
 
 }}  // namespaces
-
-#endif  // FOLLY_CONCURRENTSKIPLIST_INL_H_