#include <boost/asio/executor_work_guard.hpp>
#include <boost/asio/io_context.hpp>
+#include <boost/smart_ptr/intrusive_ptr.hpp>
+
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/uuid/uuid.hpp>
BuildComp c);
};
-
+ /// We take an `intrusive_ptr<CephContext>` to make it clear that we
+ /// will take ownership of the reference.
+ /// We take an `intrusive_ptr<CephContext>` to make it clear that we
+ /// will take ownership of the reference.
template<boost::asio::completion_token_for<BuildSig> CompletionToken>
- static auto make_with_cct(CephContext* cct,
+ static auto make_with_cct(boost::intrusive_ptr<CephContext> cct,
boost::asio::io_context& ioctx,
CompletionToken&& token) {
auto consigned = boost::asio::consign(
std::forward<CompletionToken>(token), boost::asio::make_work_guard(
boost::asio::get_associated_executor(token, ioctx.get_executor())));
return boost::asio::async_initiate<decltype(consigned), BuildSig>(
- [cct, &ioctx](auto&& handler) {
- make_with_cct_(cct, ioctx, std::move(handler));
+ [cct = std::move(cct), &ioctx](auto&& handler) mutable {
+ make_with_cct_(std::move(cct), ioctx, std::move(handler));
}, consigned);
}
+ // Prevent passing a `CephContext*`.
+
+ template<boost::asio::completion_token_for<BuildSig> CompletionToken>
+ static auto make_with_cct(CephContext* cct,
+ boost::asio::io_context& ioctx,
+ CompletionToken&& token) = delete;
+
+
static RADOS make_with_librados(librados::Rados& rados);
RADOS(const RADOS&);
friend Builder;
RADOS(std::shared_ptr<detail::Client> impl);
- static void make_with_cct_(CephContext* cct,
+ static void make_with_cct_(boost::intrusive_ptr<CephContext> cct,
boost::asio::io_context& ioctx,
BuildComp c);
if (no_mon_conf)
flags |= CINIT_FLAG_NO_MON_CONFIG;
- CephContext *cct = common_preinit(ci, env, flags);
+ boost::intrusive_ptr<CephContext> cct
+ {
+ common_preinit(ci, env, flags),
+ false //< So the intrusive_ptr adopts the reference we already have
+ };
if (cluster)
cct->_conf->cluster = *cluster;
}
if (!no_mon_conf) {
- MonClient mc_bootstrap(cct, ioctx);
+ MonClient mc_bootstrap(cct.get(), ioctx);
// TODO This function should return an error code.
auto err = mc_bootstrap.get_monmap_and_config();
if (err < 0) {
if (!cct->_log->is_started()) {
cct->_log->start();
}
- common_init_finish(cct);
+ common_init_finish(cct.get());
- RADOS::make_with_cct(cct, ioctx, std::move(c));
+ RADOS::make_with_cct(std::move(cct), ioctx, std::move(c));
}
-void RADOS::make_with_cct_(CephContext* cct,
+void RADOS::make_with_cct_(boost::intrusive_ptr<CephContext> cct,
asio::io_context& ioctx,
BuildComp c) {
try {
auto r = std::make_shared<detail::NeoClient>(
- std::make_unique<detail::RADOS>(ioctx, cct));
- r->objecter->wait_for_osd_map(
- [c = std::move(c), r = std::move(r)]() mutable {
- asio::dispatch(asio::append(std::move(c), bs::error_code{},
- RADOS{std::move(r)}));
- });
+ std::make_unique<detail::RADOS>(ioctx, std::move(cct)));
+ r->objecter->wait_for_osd_map([c = std::move(c),
+ r = std::move(r)]() mutable {
+ asio::dispatch(
+ asio::append(std::move(c), bs::error_code{}, RADOS{std::move(r)}));
+ });
} catch (const bs::system_error& err) {
asio::post(ioctx.get_executor(),
asio::append(std::move(c), err.code(), RADOS{nullptr}));
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(30s);
}
std::this_thread::sleep_for(30s);
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(30s);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(1s);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(1s);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(1s);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(1s);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(1s);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(1s);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(1s);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(500ms);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(500ms);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(50ms);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(50ms);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(50ms);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(5ms);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(5ms);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(5ms);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(5ms);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(5ms);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(5us);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(5us);
}
{
ceph::async::io_context_pool p(1);
- auto r = R::RADOS::make_with_cct(cct.get(), p,
- boost::asio::use_future).get();
+ auto r = R::RADOS::make_with_cct(cct, p, boost::asio::use_future).get();
std::this_thread::sleep_for(5us);
}
return 0;