]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/include/mempool.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / include / mempool.h
index 3b94d87205e4420c477ba39b0d8824670755d39f..155ec18d438242e0a7ce0edd99b5277846649fa4 100644 (file)
 #include <mutex>
 #include <atomic>
 #include <typeinfo>
+#include <boost/container/flat_set.hpp>
+#include <boost/container/flat_map.hpp>
 
 #include <common/Formatter.h>
-#include "include/assert.h"
+#include "include/ceph_assert.h"
 #include "include/compact_map.h"
 #include "include/compact_set.h"
 
@@ -403,6 +405,10 @@ public:
     using compact_map = compact_map<k, v, cmp,                          \
                         pool_allocator<std::pair<const k,v>>>;         \
                                                                         \
+    template<typename k,typename v, typename cmp = std::less<k> >       \
+    using compact_multimap = compact_multimap<k, v, cmp,                \
+                        pool_allocator<std::pair<const k,v>>>;         \
+                                                                        \
     template<typename k, typename cmp = std::less<k> >                  \
     using compact_set = compact_set<k, cmp, pool_allocator<k>>;         \
                                                                         \
@@ -414,6 +420,13 @@ public:
     template<typename k, typename cmp = std::less<k> >                 \
     using set = std::set<k,cmp,pool_allocator<k>>;                     \
                                                                         \
+    template<typename k, typename cmp = std::less<k> >                 \
+    using flat_set = boost::container::flat_set<k,cmp,pool_allocator<k>>; \
+                                                                       \
+    template<typename k, typename v, typename cmp = std::less<k> >     \
+    using flat_map = boost::container::flat_map<k,v,cmp,               \
+                                               pool_allocator<std::pair<k,v>>>; \
+                                                                        \
     template<typename v>                                               \
     using list = std::list<v,pool_allocator<v>>;                       \
                                                                         \
@@ -440,7 +453,40 @@ DEFINE_MEMORY_POOLS_HELPER(P)
 
 };
 
-
+// the elements allocated by mempool is in the same memory space as the ones
+// allocated by the default allocator. so compare them in an efficient way:
+// libstdc++'s std::equal is specialized to use memcmp if T is integer or
+// pointer. this is good enough for our usecase. use
+// std::is_trivially_copyable<T> to expand the support to more types if
+// nececssary.
+template<typename T, mempool::pool_index_t pool_index>
+bool operator==(const std::vector<T, std::allocator<T>>& lhs,
+               const std::vector<T, mempool::pool_allocator<pool_index, T>>& rhs)
+{
+  return (lhs.size() == rhs.size() &&
+         std::equal(lhs.begin(), lhs.end(), rhs.begin()));
+}
+
+template<typename T, mempool::pool_index_t pool_index>
+bool operator!=(const std::vector<T, std::allocator<T>>& lhs,
+               const std::vector<T, mempool::pool_allocator<pool_index, T>>& rhs)
+{
+  return !(lhs == rhs);
+}
+
+template<typename T, mempool::pool_index_t pool_index>
+bool operator==(const std::vector<T, mempool::pool_allocator<pool_index, T>>& lhs,
+               const std::vector<T, std::allocator<T>>& rhs)
+{
+  return rhs == lhs;
+}
+
+template<typename T, mempool::pool_index_t pool_index>
+bool operator!=(const std::vector<T, mempool::pool_allocator<pool_index, T>>& lhs,
+               const std::vector<T, std::allocator<T>>& rhs)
+{
+  return !(lhs == rhs);
+}
 
 // Use this for any type that is contained by a container (unless it
 // is a class you defined; see below).
@@ -468,10 +514,10 @@ DEFINE_MEMORY_POOLS_HELPER(P)
 #define MEMPOOL_CLASS_HELPERS()                                                \
   void *operator new(size_t size);                                     \
   void *operator new[](size_t size) noexcept {                         \
-    assert(0 == "no array new");                                       \
+    ceph_abort_msg("no array new");                                    \
     return nullptr; }                                                  \
   void  operator delete(void *);                                       \
-  void  operator delete[](void *) { assert(0 == "no array delete"); }
+  void  operator delete[](void *) { ceph_abort_msg("no array delete"); }
 
 
 // Use this in some particular .cc file to match each class with a