Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / win_object_handle_service.hpp @ 2486

History | View | Annotate | Download (5.8 kB)

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