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"
19 #include "include/Context.h"
20 #include "include/rados/librados.h"
21 #include "include/rados/librados.hpp"
24 struct PoolAsyncCompletionImpl
{
25 ceph::mutex lock
= ceph::make_mutex("PoolAsyncCompletionImpl lock");
26 ceph::condition_variable cond
;
29 bool released
= false;
32 rados_callback_t callback
= 0;
33 void *callback_arg
= nullptr;;
35 PoolAsyncCompletionImpl() = default;
37 int set_callback(void *cb_arg
, rados_callback_t cb
) {
38 std::scoped_lock l
{lock
};
40 callback_arg
= cb_arg
;
44 std::unique_lock l
{lock
};
45 cond
.wait(l
, [this] { return done
;});
49 std::scoped_lock l
{lock
};
52 int get_return_value() {
53 std::scoped_lock l
{lock
};
57 std::scoped_lock l
{lock
};
63 ceph_assert(!released
);
80 class C_PoolAsync_Safe
: public Context
{
81 PoolAsyncCompletionImpl
*c
;
84 explicit C_PoolAsync_Safe(PoolAsyncCompletionImpl
*_c
) : c(_c
) {
87 ~C_PoolAsync_Safe() override
{
91 void finish(int r
) override
{
98 rados_callback_t cb
= c
->callback
;
99 void *cb_arg
= c
->callback_arg
;