]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/win_object_handle_service.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / asio / detail / win_object_handle_service.hpp
1 //
2 // detail/win_object_handle_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Copyright (c) 2011 Boris Schaeling (boris@highscore.de)
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 //
11
12 #ifndef BOOST_ASIO_DETAIL_WIN_OBJECT_HANDLE_SERVICE_HPP
13 #define BOOST_ASIO_DETAIL_WIN_OBJECT_HANDLE_SERVICE_HPP
14
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 # pragma once
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
19 #include <boost/asio/detail/config.hpp>
20
21 #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
22
23 #include <boost/asio/detail/handler_alloc_helpers.hpp>
24 #include <boost/asio/detail/memory.hpp>
25 #include <boost/asio/detail/wait_handler.hpp>
26 #include <boost/asio/error.hpp>
27 #include <boost/asio/io_context.hpp>
28
29 #include <boost/asio/detail/push_options.hpp>
30
31 namespace boost {
32 namespace asio {
33 namespace detail {
34
35 class win_object_handle_service :
36 public service_base<win_object_handle_service>
37 {
38 public:
39 // The native type of an object handle.
40 typedef HANDLE native_handle_type;
41
42 // The implementation type of the object handle.
43 class implementation_type
44 {
45 public:
46 // Default constructor.
47 implementation_type()
48 : handle_(INVALID_HANDLE_VALUE),
49 wait_handle_(INVALID_HANDLE_VALUE),
50 owner_(0),
51 next_(0),
52 prev_(0)
53 {
54 }
55
56 private:
57 // Only this service will have access to the internal values.
58 friend class win_object_handle_service;
59
60 // The native object handle representation. May be accessed or modified
61 // without locking the mutex.
62 native_handle_type handle_;
63
64 // The handle used to unregister the wait operation. The mutex must be
65 // locked when accessing or modifying this member.
66 HANDLE wait_handle_;
67
68 // The operations waiting on the object handle. If there is a registered
69 // wait then the mutex must be locked when accessing or modifying this
70 // member
71 op_queue<wait_op> op_queue_;
72
73 // The service instance that owns the object handle implementation.
74 win_object_handle_service* owner_;
75
76 // Pointers to adjacent handle implementations in linked list. The mutex
77 // must be locked when accessing or modifying these members.
78 implementation_type* next_;
79 implementation_type* prev_;
80 };
81
82 // Constructor.
83 BOOST_ASIO_DECL win_object_handle_service(
84 boost::asio::io_context& io_context);
85
86 // Destroy all user-defined handler objects owned by the service.
87 BOOST_ASIO_DECL void shutdown();
88
89 // Construct a new handle implementation.
90 BOOST_ASIO_DECL void construct(implementation_type& impl);
91
92 // Move-construct a new handle implementation.
93 BOOST_ASIO_DECL void move_construct(implementation_type& impl,
94 implementation_type& other_impl);
95
96 // Move-assign from another handle implementation.
97 BOOST_ASIO_DECL void move_assign(implementation_type& impl,
98 win_object_handle_service& other_service,
99 implementation_type& other_impl);
100
101 // Destroy a handle implementation.
102 BOOST_ASIO_DECL void destroy(implementation_type& impl);
103
104 // Assign a native handle to a handle implementation.
105 BOOST_ASIO_DECL boost::system::error_code assign(implementation_type& impl,
106 const native_handle_type& handle, boost::system::error_code& ec);
107
108 // Determine whether the handle is open.
109 bool is_open(const implementation_type& impl) const
110 {
111 return impl.handle_ != INVALID_HANDLE_VALUE && impl.handle_ != 0;
112 }
113
114 // Destroy a handle implementation.
115 BOOST_ASIO_DECL boost::system::error_code close(implementation_type& impl,
116 boost::system::error_code& ec);
117
118 // Get the native handle representation.
119 native_handle_type native_handle(const implementation_type& impl) const
120 {
121 return impl.handle_;
122 }
123
124 // Cancel all operations associated with the handle.
125 BOOST_ASIO_DECL boost::system::error_code cancel(implementation_type& impl,
126 boost::system::error_code& ec);
127
128 // Perform a synchronous wait for the object to enter a signalled state.
129 BOOST_ASIO_DECL void wait(implementation_type& impl,
130 boost::system::error_code& ec);
131
132 /// Start an asynchronous wait.
133 template <typename Handler>
134 void async_wait(implementation_type& impl, Handler& handler)
135 {
136 // Allocate and construct an operation to wrap the handler.
137 typedef wait_handler<Handler> op;
138 typename op::ptr p = { boost::asio::detail::addressof(handler),
139 op::ptr::allocate(handler), 0 };
140 p.p = new (p.v) op(handler);
141
142 BOOST_ASIO_HANDLER_CREATION((io_context_.context(), *p.p, "object_handle",
143 &impl, reinterpret_cast<uintmax_t>(impl.wait_handle_), "async_wait"));
144
145 start_wait_op(impl, p.p);
146 p.v = p.p = 0;
147 }
148
149 private:
150 // Helper function to start an asynchronous wait operation.
151 BOOST_ASIO_DECL void start_wait_op(implementation_type& impl, wait_op* op);
152
153 // Helper function to register a wait operation.
154 BOOST_ASIO_DECL void register_wait_callback(
155 implementation_type& impl, mutex::scoped_lock& lock);
156
157 // Callback function invoked when the registered wait completes.
158 static BOOST_ASIO_DECL VOID CALLBACK wait_callback(
159 PVOID param, BOOLEAN timeout);
160
161 // The io_context implementation used to post completions.
162 io_context_impl& io_context_;
163
164 // Mutex to protect access to internal state.
165 mutex mutex_;
166
167 // The head of a linked list of all implementations.
168 implementation_type* impl_list_;
169
170 // Flag to indicate that the dispatcher has been shut down.
171 bool shutdown_;
172 };
173
174 } // namespace detail
175 } // namespace asio
176 } // namespace boost
177
178 #include <boost/asio/detail/pop_options.hpp>
179
180 #if defined(BOOST_ASIO_HEADER_ONLY)
181 # include <boost/asio/detail/impl/win_object_handle_service.ipp>
182 #endif // defined(BOOST_ASIO_HEADER_ONLY)
183
184 #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
185
186 #endif // BOOST_ASIO_DETAIL_WIN_OBJECT_HANDLE_SERVICE_HPP