]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/asio/detail/win_iocp_overlapped_ptr.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / asio / detail / win_iocp_overlapped_ptr.hpp
index 6cff7ae1d4aa79f7e3fe9674c34abc12660f580a..d1ed1cb1a0e8a6479dda95b9aab737191fc42a3e 100644 (file)
@@ -2,7 +2,7 @@
 // detail/win_iocp_overlapped_ptr.hpp
 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 //
-// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 //
 // Distributed under the Boost Software License, Version 1.0. (See accompanying
 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -21,6 +21,7 @@
 
 #include <boost/asio/io_context.hpp>
 #include <boost/asio/detail/handler_alloc_helpers.hpp>
+#include <boost/asio/detail/io_object_executor.hpp>
 #include <boost/asio/detail/memory.hpp>
 #include <boost/asio/detail/noncopyable.hpp>
 #include <boost/asio/detail/win_iocp_overlapped_op.hpp>
@@ -45,13 +46,13 @@ public:
   }
 
   // Construct an win_iocp_overlapped_ptr to contain the specified handler.
-  template <typename Handler>
-  explicit win_iocp_overlapped_ptr(
-      boost::asio::io_context& io_context, BOOST_ASIO_MOVE_ARG(Handler) handler)
+  template <typename Executor, typename Handler>
+  explicit win_iocp_overlapped_ptr(const Executor& ex,
+      BOOST_ASIO_MOVE_ARG(Handler) handler)
     : ptr_(0),
       iocp_service_(0)
   {
-    this->reset(io_context, BOOST_ASIO_MOVE_CAST(Handler)(handler));
+    this->reset(ex, BOOST_ASIO_MOVE_CAST(Handler)(handler));
   }
 
   // Destructor automatically frees the OVERLAPPED object unless released.
@@ -74,22 +75,25 @@ public:
 
   // Reset to contain the specified handler, freeing any current OVERLAPPED
   // object.
-  template <typename Handler>
-  void reset(boost::asio::io_context& io_context, Handler handler)
+  template <typename Executor, typename Handler>
+  void reset(const Executor& ex, Handler handler)
   {
-    typedef win_iocp_overlapped_op<Handler> op;
+    const bool native = is_same<Executor, io_context::executor_type>::value;
+    win_iocp_io_context* iocp_service = this->get_iocp_service(ex);
+
+    typedef win_iocp_overlapped_op<Handler, io_object_executor<Executor> > op;
     typename op::ptr p = { boost::asio::detail::addressof(handler),
       op::ptr::allocate(handler), 0 };
-    p.p = new (p.v) op(handler);
+    p.p = new (p.v) op(handler, io_object_executor<Executor>(ex, native));
 
-    BOOST_ASIO_HANDLER_CREATION((io_context, *p.p,
-          "io_context", &io_context.impl_, 0, "overlapped"));
+    BOOST_ASIO_HANDLER_CREATION((ex.context(), *p.p,
+          "iocp_service", iocp_service, 0, "overlapped"));
 
-    io_context.impl_.work_started();
+    iocp_service->work_started();
     reset();
     ptr_ = p.p;
     p.v = p.p = 0;
-    iocp_service_ = &io_context.impl_;
+    iocp_service_ = iocp_service;
   }
 
   // Get the contained OVERLAPPED object.
@@ -130,6 +134,18 @@ public:
   }
 
 private:
+  template <typename Executor>
+  static win_iocp_io_context* get_iocp_service(const Executor& ex)
+  {
+    return &use_service<win_iocp_io_context>(ex.context());
+  }
+
+  static win_iocp_io_context* get_iocp_service(
+      const io_context::executor_type& ex)
+  {
+    return &ex.context().impl_;
+  }
+
   win_iocp_operation* ptr_;
   win_iocp_io_context* iocp_service_;
 };