1616
1717#include < boost/asio/associated_cancellation_slot.hpp>
1818#include < boost/asio/cancellation_type.hpp>
19+ #include < boost/asio/execution/executor.hpp>
1920
2021#include " include/rados/librados.hpp"
2122#include " common/async/completion.h"
@@ -151,136 +152,142 @@ struct AsyncOp : Invoker<Result> {
151152// /
152153// / The given IoCtx reference is not required to remain valid, but some IoCtx
153154// / instance must preserve its underlying implementation until completion.
154- template <typename ExecutionContext , typename CompletionToken>
155- auto async_read (ExecutionContext& ctx , IoCtx& io, const std::string& oid,
155+ template <boost::asio::execution::executor IoExecutor , typename CompletionToken>
156+ auto async_read (IoExecutor ex , IoCtx& io, const std::string& oid,
156157 size_t len, uint64_t off, CompletionToken&& token)
157158{
158159 using Op = detail::AsyncOp<bufferlist>;
159160 using Signature = typename Op::Signature;
160161 return boost::asio::async_initiate<CompletionToken, Signature>(
161- [] (auto handler, auto ex, IoCtx& io, const std::string& oid ,
162- size_t len, uint64_t off) {
162+ [] (auto handler, IoExecutor ex, const IoCtx& i ,
163+ const std::string& oid, size_t len, uint64_t off) {
163164 constexpr bool is_read = true ;
164165 auto p = Op::create (ex, is_read, std::move (handler));
165166 auto & op = p->user_data ;
166167
168+ IoCtx& io = const_cast <IoCtx&>(i);
167169 int ret = io.aio_read (oid, op.aio_completion .get (), &op.result , len, off);
168170 if (ret < 0 ) {
169171 auto ec = boost::system::error_code{-ret, librados::detail::err_category ()};
170172 ceph::async::post (std::move (p), ec, 0 , bufferlist{});
171173 } else {
172174 p.release (); // release ownership until completion
173175 }
174- }, token, ctx. get_executor () , io, oid, len, off);
176+ }, token, ex , io, oid, len, off);
175177}
176178
177179// / Calls IoCtx::aio_write() and arranges for the AioCompletion to call a
178180// / given handler with signature (error_code, version_t).
179181// /
180182// / The given IoCtx reference is not required to remain valid, but some IoCtx
181183// / instance must preserve its underlying implementation until completion.
182- template <typename ExecutionContext , typename CompletionToken>
183- auto async_write (ExecutionContext& ctx , IoCtx& io, const std::string& oid,
184+ template <boost::asio::execution::executor IoExecutor , typename CompletionToken>
185+ auto async_write (IoExecutor ex , IoCtx& io, const std::string& oid,
184186 const bufferlist &bl, size_t len, uint64_t off,
185187 CompletionToken&& token)
186188{
187189 using Op = detail::AsyncOp<void >;
188190 using Signature = typename Op::Signature;
189191 return boost::asio::async_initiate<CompletionToken, Signature>(
190- [] (auto handler, auto ex, IoCtx& io , const std::string& oid,
192+ [] (auto handler, IoExecutor ex, const IoCtx& i , const std::string& oid,
191193 const bufferlist &bl, size_t len, uint64_t off) {
192194 constexpr bool is_read = false ;
193195 auto p = Op::create (ex, is_read, std::move (handler));
194196 auto & op = p->user_data ;
195197
198+ IoCtx& io = const_cast <IoCtx&>(i);
196199 int ret = io.aio_write (oid, op.aio_completion .get (), bl, len, off);
197200 if (ret < 0 ) {
198201 auto ec = boost::system::error_code{-ret, librados::detail::err_category ()};
199202 ceph::async::post (std::move (p), ec, 0 );
200203 } else {
201204 p.release (); // release ownership until completion
202205 }
203- }, token, ctx. get_executor () , io, oid, bl, len, off);
206+ }, token, ex , io, oid, bl, len, off);
204207}
205208
206209// / Calls IoCtx::aio_operate() and arranges for the AioCompletion to call a
207210// / given handler with signature (error_code, version_t, bufferlist).
208211// /
209212// / The given IoCtx reference is not required to remain valid, but some IoCtx
210213// / instance must preserve its underlying implementation until completion.
211- template <typename ExecutionContext , typename CompletionToken>
212- auto async_operate (ExecutionContext& ctx , IoCtx& io, const std::string& oid,
213- ObjectReadOperation * read_op, int flags,
214+ template <boost::asio::execution::executor IoExecutor , typename CompletionToken>
215+ auto async_operate (IoExecutor ex , IoCtx& io, const std::string& oid,
216+ ObjectReadOperation read_op, int flags,
214217 const jspan_context* trace_ctx, CompletionToken&& token)
215218{
216219 using Op = detail::AsyncOp<bufferlist>;
217220 using Signature = typename Op::Signature;
218221 return boost::asio::async_initiate<CompletionToken, Signature>(
219- [] (auto handler, auto ex, IoCtx& io , const std::string& oid,
220- ObjectReadOperation * read_op, int flags) {
222+ [] (auto handler, IoExecutor ex, const IoCtx& i , const std::string& oid,
223+ ObjectReadOperation read_op, int flags) {
221224 constexpr bool is_read = true ;
222225 auto p = Op::create (ex, is_read, std::move (handler));
223226 auto & op = p->user_data ;
224227
225- int ret = io.aio_operate (oid, op.aio_completion .get (), read_op,
228+ auto & io = const_cast <IoCtx&>(i);
229+ int ret = io.aio_operate (oid, op.aio_completion .get (), &read_op,
226230 flags, &op.result );
227231 if (ret < 0 ) {
228232 auto ec = boost::system::error_code{-ret, librados::detail::err_category ()};
229233 ceph::async::post (std::move (p), ec, 0 , bufferlist{});
230234 } else {
231235 p.release (); // release ownership until completion
232236 }
233- }, token, ctx. get_executor () , io, oid, read_op, flags);
237+ }, token, ex , io, oid, std::move ( read_op) , flags);
234238}
235239
236240// / Calls IoCtx::aio_operate() and arranges for the AioCompletion to call a
237241// / given handler with signature (error_code, version_t).
238242// /
239243// / The given IoCtx reference is not required to remain valid, but some IoCtx
240244// / instance must preserve its underlying implementation until completion.
241- template <typename ExecutionContext , typename CompletionToken>
242- auto async_operate (ExecutionContext& ctx , IoCtx& io, const std::string& oid,
243- ObjectWriteOperation * write_op, int flags,
245+ template <boost::asio::execution::executor IoExecutor , typename CompletionToken>
246+ auto async_operate (IoExecutor ex , IoCtx& io, const std::string& oid,
247+ ObjectWriteOperation write_op, int flags,
244248 const jspan_context* trace_ctx, CompletionToken &&token)
245249{
246250 using Op = detail::AsyncOp<void >;
247251 using Signature = typename Op::Signature;
248252 return boost::asio::async_initiate<CompletionToken, Signature>(
249- [] (auto handler, auto ex, IoCtx& io , const std::string& oid,
250- ObjectWriteOperation * write_op, int flags,
253+ [] (auto handler, IoExecutor ex, const IoCtx& i , const std::string& oid,
254+ ObjectWriteOperation write_op, int flags,
251255 const jspan_context* trace_ctx) {
252256 constexpr bool is_read = false ;
253257 auto p = Op::create (ex, is_read, std::move (handler));
254258 auto & op = p->user_data ;
255259
256- int ret = io.aio_operate (oid, op.aio_completion .get (), write_op, flags, trace_ctx);
260+ auto & io = const_cast <IoCtx&>(i);
261+ int ret = io.aio_operate (oid, op.aio_completion .get (), &write_op, flags, trace_ctx);
257262 if (ret < 0 ) {
258263 auto ec = boost::system::error_code{-ret, librados::detail::err_category ()};
259264 ceph::async::post (std::move (p), ec, 0 );
260265 } else {
261266 p.release (); // release ownership until completion
262267 }
263- }, token, ctx. get_executor () , io, oid, write_op, flags, trace_ctx);
268+ }, token, ex , io, oid, std::move ( write_op) , flags, trace_ctx);
264269}
265270
266271// / Calls IoCtx::aio_notify() and arranges for the AioCompletion to call a
267272// / given handler with signature (error_code, version_t, bufferlist).
268273// /
269274// / The given IoCtx reference is not required to remain valid, but some IoCtx
270275// / instance must preserve its underlying implementation until completion.
271- template <typename ExecutionContext , typename CompletionToken>
272- auto async_notify (ExecutionContext& ctx , IoCtx& io, const std::string& oid,
276+ template <boost::asio::execution::executor IoExecutor , typename CompletionToken>
277+ auto async_notify (IoExecutor ex , IoCtx& io, const std::string& oid,
273278 bufferlist& bl, uint64_t timeout_ms, CompletionToken &&token)
274279{
275280 using Op = detail::AsyncOp<bufferlist>;
276281 using Signature = typename Op::Signature;
277282 return boost::asio::async_initiate<CompletionToken, Signature>(
278- [] (auto handler, auto ex, IoCtx& io , const std::string& oid,
279- bufferlist& bl , uint64_t timeout_ms) {
283+ [] (auto handler, IoExecutor ex, const IoCtx& i , const std::string& oid,
284+ const bufferlist& b , uint64_t timeout_ms) {
280285 constexpr bool is_read = false ;
281286 auto p = Op::create (ex, is_read, std::move (handler));
282287 auto & op = p->user_data ;
283288
289+ IoCtx& io = const_cast <IoCtx&>(i);
290+ bufferlist& bl = const_cast <bufferlist&>(b);
284291 int ret = io.aio_notify (oid, op.aio_completion .get (),
285292 bl, timeout_ms, &op.result );
286293 if (ret < 0 ) {
@@ -289,7 +296,7 @@ auto async_notify(ExecutionContext& ctx, IoCtx& io, const std::string& oid,
289296 } else {
290297 p.release (); // release ownership until completion
291298 }
292- }, token, ctx. get_executor () , io, oid, bl, timeout_ms);
299+ }, token, ex , io, oid, bl, timeout_ms);
293300}
294301
295302} // namespace librados
0 commit comments