annotate DEPENDENCIES/generic/include/boost/asio/detail/win_object_handle_service.hpp @ 133:4acb5d8d80b6 tip

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