]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/asio/test/deadline_timer.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / asio / test / deadline_timer.cpp
index 0ff0d9bd82fd2446b71bb90d967683c4c6d60782..c6ce397bacb6cb2a914d01496a154387749371ce 100644 (file)
@@ -250,21 +250,77 @@ struct custom_allocation_timer_handler
   custom_allocation_timer_handler(int* count) : count_(count) {}
   void operator()(const boost::system::error_code&) {}
   int* count_;
-};
 
-void* asio_handler_allocate(std::size_t size,
-    custom_allocation_timer_handler* handler)
-{
-  ++(*handler->count_);
-  return ::operator new(size);
-}
-
-void asio_handler_deallocate(void* pointer, std::size_t,
-    custom_allocation_timer_handler* handler)
-{
-  --(*handler->count_);
-  ::operator delete(pointer);
-}
+  template <typename T>
+  struct allocator
+  {
+    typedef size_t size_type;
+    typedef ptrdiff_t difference_type;
+    typedef T* pointer;
+    typedef const T* const_pointer;
+    typedef T& reference;
+    typedef const T& const_reference;
+    typedef T value_type;
+
+    template <typename U>
+    struct rebind
+    {
+      typedef allocator<U> other;
+    };
+
+    explicit allocator(int* count) BOOST_ASIO_NOEXCEPT
+      : count_(count)
+    {
+    }
+
+    allocator(const allocator& other) BOOST_ASIO_NOEXCEPT
+      : count_(other.count_)
+    {
+    }
+
+    template <typename U>
+    allocator(const allocator<U>& other) BOOST_ASIO_NOEXCEPT
+      : count_(other.count_)
+    {
+    }
+
+    pointer allocate(size_type n, const void* = 0)
+    {
+      ++(*count_);
+      return static_cast<T*>(::operator new(sizeof(T) * n));
+    }
+
+    void deallocate(pointer p, size_type)
+    {
+      --(*count_);
+      ::operator delete(p);
+    }
+
+    size_type max_size() const
+    {
+      return ~size_type(0);
+    }
+
+    void construct(pointer p, const T& v)
+    {
+      new (p) T(v);
+    }
+
+    void destroy(pointer p)
+    {
+      p->~T();
+    }
+
+    int* count_;
+  };
+
+  typedef allocator<int> allocator_type;
+
+  allocator_type get_allocator() const BOOST_ASIO_NOEXCEPT
+  {
+    return allocator_type(count_);
+  }
+};
 
 void deadline_timer_custom_allocation_test()
 {