diff options
Diffstat (limited to '3rdparty/asio/src/tests/unit/deadline_timer.cpp')
-rw-r--r-- | 3rdparty/asio/src/tests/unit/deadline_timer.cpp | 92 |
1 files changed, 72 insertions, 20 deletions
diff --git a/3rdparty/asio/src/tests/unit/deadline_timer.cpp b/3rdparty/asio/src/tests/unit/deadline_timer.cpp index 9c48b62c69a..9bc7f16fcd2 100644 --- a/3rdparty/asio/src/tests/unit/deadline_timer.cpp +++ b/3rdparty/asio/src/tests/unit/deadline_timer.cpp @@ -2,7 +2,7 @@ // deadline_timer.cpp // ~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -20,7 +20,7 @@ #if defined(ASIO_HAS_BOOST_DATE_TIME) -#include <boost/bind.hpp> +#include <boost/bind/bind.hpp> #include "archetypes/async_result.hpp" #include "asio/executor_work_guard.hpp" #include "asio/io_context.hpp" @@ -250,21 +250,77 @@ struct custom_allocation_timer_handler custom_allocation_timer_handler(int* count) : count_(count) {} void operator()(const asio::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) noexcept + : count_(count) + { + } + + allocator(const allocator& other) noexcept + : count_(other.count_) + { + } + + template <typename U> + allocator(const allocator<U>& other) 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 noexcept + { + return allocator_type(count_); + } +}; void deadline_timer_custom_allocation_test() { @@ -340,7 +396,6 @@ void deadline_timer_async_result_test() ioc.run(); } -#if defined(ASIO_HAS_MOVE) asio::deadline_timer make_timer(asio::io_context& ioc, int* count) { asio::deadline_timer t(ioc); @@ -348,11 +403,9 @@ asio::deadline_timer make_timer(asio::io_context& ioc, int* count) t.async_wait(boost::bind(increment, count)); return t; } -#endif // defined(ASIO_HAS_MOVE) void deadline_timer_move_test() { -#if defined(ASIO_HAS_MOVE) asio::io_context io_context1; asio::io_context io_context2; int count = 0; @@ -370,7 +423,6 @@ void deadline_timer_move_test() io_context1.run(); ASIO_CHECK(count == 2); -#endif // defined(ASIO_HAS_MOVE) } ASIO_TEST_SUITE |