1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2012 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_LIBRADOS_POOLASYNCCOMPLETIONIMPL_H
16 #define CEPH_LIBRADOS_POOLASYNCCOMPLETIONIMPL_H
18 #include "common/ceph_mutex.h"
20 #include <boost/intrusive_ptr.hpp>
22 #include "include/rados/librados.h"
23 #include "include/rados/librados.hpp"
26 struct PoolAsyncCompletionImpl
{
27 ceph::mutex lock
= ceph::make_mutex("PoolAsyncCompletionImpl lock");
28 ceph::condition_variable cond
;
31 bool released
= false;
34 rados_callback_t callback
= nullptr;
35 void *callback_arg
= nullptr;
37 PoolAsyncCompletionImpl() = default;
39 int set_callback(void *cb_arg
, rados_callback_t cb
) {
40 std::scoped_lock
l(lock
);
42 callback_arg
= cb_arg
;
46 std::unique_lock
l(lock
);
52 std::scoped_lock
l(lock
);
55 int get_return_value() {
56 std::scoped_lock
l(lock
);
60 std::scoped_lock
l(lock
);
65 std::scoped_lock
l(lock
);
66 ceph_assert(!released
);
70 std::unique_lock
l(lock
);
78 inline void intrusive_ptr_add_ref(PoolAsyncCompletionImpl
* p
) {
81 inline void intrusive_ptr_release(PoolAsyncCompletionImpl
* p
) {
85 class CB_PoolAsync_Safe
{
86 boost::intrusive_ptr
<PoolAsyncCompletionImpl
> p
;
89 explicit CB_PoolAsync_Safe(boost::intrusive_ptr
<PoolAsyncCompletionImpl
> p
)
91 ~CB_PoolAsync_Safe() = default;
93 void operator()(int r
) {
95 std::unique_lock
l(c
->lock
);
101 rados_callback_t cb
= c
->callback
;
102 void *cb_arg
= c
->callback_arg
;