Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:54

0001 //
0002 // impl/cancellation_signal.ipp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_IMPL_CANCELLATION_SIGNAL_IPP
0012 #define BOOST_ASIO_IMPL_CANCELLATION_SIGNAL_IPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/cancellation_signal.hpp>
0020 #include <boost/asio/detail/thread_context.hpp>
0021 #include <boost/asio/detail/thread_info_base.hpp>
0022 
0023 #include <boost/asio/detail/push_options.hpp>
0024 
0025 namespace boost {
0026 namespace asio {
0027 
0028 cancellation_signal::~cancellation_signal()
0029 {
0030   if (handler_)
0031   {
0032     std::pair<void*, std::size_t> mem = handler_->destroy();
0033     detail::thread_info_base::deallocate(
0034         detail::thread_info_base::cancellation_signal_tag(),
0035         detail::thread_context::top_of_thread_call_stack(),
0036         mem.first, mem.second);
0037   }
0038 }
0039 
0040 void cancellation_slot::clear()
0041 {
0042   if (handler_ != 0 && *handler_ != 0)
0043   {
0044     std::pair<void*, std::size_t> mem = (*handler_)->destroy();
0045     detail::thread_info_base::deallocate(
0046         detail::thread_info_base::cancellation_signal_tag(),
0047         detail::thread_context::top_of_thread_call_stack(),
0048         mem.first, mem.second);
0049     *handler_ = 0;
0050   }
0051 }
0052 
0053 std::pair<void*, std::size_t> cancellation_slot::prepare_memory(
0054     std::size_t size, std::size_t align)
0055 {
0056   assert(handler_);
0057   std::pair<void*, std::size_t> mem;
0058   if (*handler_)
0059   {
0060     mem = (*handler_)->destroy();
0061     *handler_ = 0;
0062   }
0063   if (size > mem.second
0064       || reinterpret_cast<std::size_t>(mem.first) % align != 0)
0065   {
0066     if (mem.first)
0067     {
0068       detail::thread_info_base::deallocate(
0069           detail::thread_info_base::cancellation_signal_tag(),
0070           detail::thread_context::top_of_thread_call_stack(),
0071           mem.first, mem.second);
0072     }
0073     mem.first = detail::thread_info_base::allocate(
0074         detail::thread_info_base::cancellation_signal_tag(),
0075         detail::thread_context::top_of_thread_call_stack(),
0076         size, align);
0077     mem.second = size;
0078   }
0079   return mem;
0080 }
0081 
0082 cancellation_slot::auto_delete_helper::~auto_delete_helper()
0083 {
0084   if (mem.first)
0085   {
0086     detail::thread_info_base::deallocate(
0087         detail::thread_info_base::cancellation_signal_tag(),
0088         detail::thread_context::top_of_thread_call_stack(),
0089         mem.first, mem.second);
0090   }
0091 }
0092 
0093 } // namespace asio
0094 } // namespace boost
0095 
0096 #include <boost/asio/detail/pop_options.hpp>
0097 
0098 #endif // BOOST_ASIO_IMPL_CANCELLATION_SIGNAL_IPP