]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/asio/detail/bulk_executor_op.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / asio / detail / bulk_executor_op.hpp
CommitLineData
20effc67
TL
1//
2// detail/bulk_executor_op.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4//
1e59de90 5// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
20effc67
TL
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_DETAIL_BULK_EXECUTOR_OP_HPP
12#define BOOST_ASIO_DETAIL_BULK_EXECUTOR_OP_HPP
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/detail/bind_handler.hpp>
20#include <boost/asio/detail/fenced_block.hpp>
21#include <boost/asio/detail/handler_alloc_helpers.hpp>
22#include <boost/asio/detail/handler_invoke_helpers.hpp>
23#include <boost/asio/detail/scheduler_operation.hpp>
24
25#include <boost/asio/detail/push_options.hpp>
26
27namespace boost {
28namespace asio {
29namespace detail {
30
31template <typename Handler, typename Alloc,
32 typename Operation = scheduler_operation>
33class bulk_executor_op : public Operation
34{
35public:
36 BOOST_ASIO_DEFINE_HANDLER_ALLOCATOR_PTR(bulk_executor_op);
37
38 template <typename H>
39 bulk_executor_op(BOOST_ASIO_MOVE_ARG(H) h,
40 const Alloc& allocator, std::size_t i)
41 : Operation(&bulk_executor_op::do_complete),
42 handler_(BOOST_ASIO_MOVE_CAST(H)(h)),
43 allocator_(allocator),
44 index_(i)
45 {
46 }
47
48 static void do_complete(void* owner, Operation* base,
49 const boost::system::error_code& /*ec*/,
50 std::size_t /*bytes_transferred*/)
51 {
52 // Take ownership of the handler object.
53 bulk_executor_op* o(static_cast<bulk_executor_op*>(base));
54 Alloc allocator(o->allocator_);
55 ptr p = { detail::addressof(allocator), o, o };
56
57 BOOST_ASIO_HANDLER_COMPLETION((*o));
58
59 // Make a copy of the handler so that the memory can be deallocated before
60 // the upcall is made. Even if we're not about to make an upcall, a
61 // sub-object of the handler may be the true owner of the memory associated
62 // with the handler. Consequently, a local copy of the handler is required
63 // to ensure that any owning sub-object remains valid until after we have
64 // deallocated the memory here.
65 detail::binder1<Handler, std::size_t> handler(o->handler_, o->index_);
66 p.reset();
67
68 // Make the upcall if required.
69 if (owner)
70 {
71 fenced_block b(fenced_block::half);
72 BOOST_ASIO_HANDLER_INVOCATION_BEGIN(());
73 boost_asio_handler_invoke_helpers::invoke(handler, handler.handler_);
74 BOOST_ASIO_HANDLER_INVOCATION_END;
75 }
76 }
77
78private:
79 Handler handler_;
80 Alloc allocator_;
81 std::size_t index_;
82};
83
84} // namespace detail
85} // namespace asio
86} // namespace boost
87
88#include <boost/asio/detail/pop_options.hpp>
89
90#endif // BOOST_ASIO_DETAIL_BULK_EXECUTOR_OP_HPP