]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/AsioEngine.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / AsioEngine.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_LIBRBD_ASIO_ENGINE_H
5 #define CEPH_LIBRBD_ASIO_ENGINE_H
6
7 #include "include/common_fwd.h"
8 #include "include/rados/librados_fwd.hpp"
9 #include <memory>
10 #include <boost/asio/dispatch.hpp>
11 #include <boost/asio/io_context.hpp>
12 #include <boost/asio/io_context_strand.hpp>
13 #include <boost/asio/post.hpp>
14
15 struct Context;
16 namespace neorados { struct RADOS; }
17
18 namespace librbd {
19
20 namespace asio { struct ContextWQ; }
21
22 class AsioEngine {
23 public:
24 explicit AsioEngine(std::shared_ptr<librados::Rados> rados);
25 explicit AsioEngine(librados::IoCtx& io_ctx);
26 ~AsioEngine();
27
28 AsioEngine(AsioEngine&&) = delete;
29 AsioEngine(const AsioEngine&) = delete;
30 AsioEngine& operator=(const AsioEngine&) = delete;
31
32 inline neorados::RADOS& get_rados_api() {
33 return *m_rados_api;
34 }
35
36 inline boost::asio::io_context& get_io_context() {
37 return m_io_context;
38 }
39 inline operator boost::asio::io_context&() {
40 return m_io_context;
41 }
42
43 using executor_type = boost::asio::io_context::executor_type;
44 inline executor_type get_executor() {
45 return m_io_context.get_executor();
46 }
47
48 inline boost::asio::io_context::strand& get_api_strand() {
49 // API client callbacks should never fire concurrently
50 return *m_api_strand;
51 }
52
53 inline asio::ContextWQ* get_work_queue() {
54 return m_context_wq.get();
55 }
56
57 template <typename T>
58 void dispatch(T&& t) {
59 boost::asio::dispatch(m_io_context, std::forward<T>(t));
60 }
61 void dispatch(Context* ctx, int r);
62
63 template <typename T>
64 void post(T&& t) {
65 boost::asio::post(m_io_context, std::forward<T>(t));
66 }
67 void post(Context* ctx, int r);
68
69 private:
70 std::shared_ptr<neorados::RADOS> m_rados_api;
71 CephContext* m_cct;
72
73 boost::asio::io_context& m_io_context;
74 std::unique_ptr<boost::asio::io_context::strand> m_api_strand;
75 std::unique_ptr<asio::ContextWQ> m_context_wq;
76 };
77
78 } // namespace librbd
79
80 #endif // CEPH_LIBRBD_ASIO_ENGINE_H