]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // |
2 | // impl/cancellation_signal.ipp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
5 | // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) | |
6 | // | |
7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
9 | // | |
10 | ||
11 | #ifndef BOOST_ASIO_IMPL_CANCELLATION_SIGNAL_IPP | |
12 | #define BOOST_ASIO_IMPL_CANCELLATION_SIGNAL_IPP | |
13 | ||
14 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) | |
15 | # pragma once | |
16 | #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) | |
17 | ||
18 | #include <boost/asio/detail/config.hpp> | |
19 | #include <boost/asio/cancellation_signal.hpp> | |
20 | #include <boost/asio/detail/thread_context.hpp> | |
21 | #include <boost/asio/detail/thread_info_base.hpp> | |
22 | ||
23 | #include <boost/asio/detail/push_options.hpp> | |
24 | ||
25 | namespace boost { | |
26 | namespace asio { | |
27 | ||
28 | cancellation_signal::~cancellation_signal() | |
29 | { | |
30 | if (handler_) | |
31 | { | |
32 | std::pair<void*, std::size_t> mem = handler_->destroy(); | |
33 | detail::thread_info_base::deallocate( | |
34 | detail::thread_info_base::cancellation_signal_tag(), | |
35 | detail::thread_context::top_of_thread_call_stack(), | |
36 | mem.first, mem.second); | |
37 | } | |
38 | } | |
39 | ||
40 | void cancellation_slot::clear() | |
41 | { | |
42 | if (handler_ != 0 && *handler_ != 0) | |
43 | { | |
44 | std::pair<void*, std::size_t> mem = (*handler_)->destroy(); | |
45 | detail::thread_info_base::deallocate( | |
46 | detail::thread_info_base::cancellation_signal_tag(), | |
47 | detail::thread_context::top_of_thread_call_stack(), | |
48 | mem.first, mem.second); | |
49 | *handler_ = 0; | |
50 | } | |
51 | } | |
52 | ||
53 | std::pair<void*, std::size_t> cancellation_slot::prepare_memory( | |
54 | std::size_t size, std::size_t align) | |
55 | { | |
56 | assert(handler_); | |
57 | std::pair<void*, std::size_t> mem; | |
58 | if (*handler_) | |
59 | { | |
60 | mem = (*handler_)->destroy(); | |
61 | *handler_ = 0; | |
62 | } | |
63 | if (size > mem.second | |
64 | || reinterpret_cast<std::size_t>(mem.first) % align != 0) | |
65 | { | |
66 | if (mem.first) | |
67 | { | |
68 | detail::thread_info_base::deallocate( | |
69 | detail::thread_info_base::cancellation_signal_tag(), | |
70 | detail::thread_context::top_of_thread_call_stack(), | |
71 | mem.first, mem.second); | |
72 | } | |
73 | mem.first = detail::thread_info_base::allocate( | |
74 | detail::thread_info_base::cancellation_signal_tag(), | |
75 | detail::thread_context::top_of_thread_call_stack(), | |
76 | size, align); | |
77 | mem.second = size; | |
78 | } | |
79 | return mem; | |
80 | } | |
81 | ||
82 | cancellation_slot::auto_delete_helper::~auto_delete_helper() | |
83 | { | |
84 | if (mem.first) | |
85 | { | |
86 | detail::thread_info_base::deallocate( | |
87 | detail::thread_info_base::cancellation_signal_tag(), | |
88 | detail::thread_context::top_of_thread_call_stack(), | |
89 | mem.first, mem.second); | |
90 | } | |
91 | } | |
92 | ||
93 | } // namespace asio | |
94 | } // namespace boost | |
95 | ||
96 | #include <boost/asio/detail/pop_options.hpp> | |
97 | ||
98 | #endif // BOOST_ASIO_IMPL_CANCELLATION_SIGNAL_IPP |