Make folly's T_CHECK_TIMEOUT/T_CHECK_TIME_LT use SKIP() on failure
[folly.git] / folly / ThreadCachedArena.h
index 8e9f0aef7915a7e4e78b003e82f1e41ee326a7b2..e34a618dfa4b41f86cf5ecfe99de26f86e3587ff 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #ifndef FOLLY_THREADCACHEDARENA_H_
 #define FOLLY_THREADCACHEDARENA_H_
 
-#include <utility>
-#include <mutex>
-#include <limits>
-#include <boost/intrusive/slist.hpp>
+#include <type_traits>
 
-#include "folly/Likely.h"
-#include "folly/Arena.h"
-#include "folly/ThreadLocal.h"
+#include <folly/Arena.h>
+#include <folly/Likely.h>
+#include <folly/Synchronized.h>
+#include <folly/ThreadLocal.h>
 
 namespace folly {
 
@@ -42,7 +40,8 @@ namespace folly {
 class ThreadCachedArena {
  public:
   explicit ThreadCachedArena(
-      size_t minBlockSize = SysArena::kDefaultMinBlockSize);
+      size_t minBlockSize = SysArena::kDefaultMinBlockSize,
+      size_t maxAlign = SysArena::kDefaultMaxAlign);
 
   void* allocate(size_t size) {
     SysArena* arena = arena_.get();
@@ -57,7 +56,12 @@ class ThreadCachedArena {
     // Deallocate? Never!
   }
 
+  // Gets the total memory used by the arena
+  size_t totalSize() const;
+
  private:
+  struct ThreadLocalPtrTag {};
+
   ThreadCachedArena(const ThreadCachedArena&) = delete;
   ThreadCachedArena(ThreadCachedArena&&) = delete;
   ThreadCachedArena& operator=(const ThreadCachedArena&) = delete;
@@ -69,13 +73,18 @@ class ThreadCachedArena {
   // the ThreadCachedArena is destroyed.
   void zombify(SysArena&& arena);
 
-  size_t minBlockSize_;
-  SysArena zombies_;  // allocated from threads that are now dead
-  std::mutex zombiesMutex_;
-  ThreadLocalPtr<SysArena> arena_;  // per-thread arena
+  const size_t minBlockSize_;
+  const size_t maxAlign_;
+
+  ThreadLocalPtr<SysArena, ThreadLocalPtrTag> arena_;  // Per-thread arena.
+
+  // Allocations from threads that are now dead.
+  Synchronized<SysArena> zombies_;
 };
 
+template <>
+struct IsArenaAllocator<ThreadCachedArena> : std::true_type { };
+
 }  // namespace folly
 
 #endif /* FOLLY_THREADCACHEDARENA_H_ */
-