]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/Cond.h
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-2006 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.
19 #include "include/Context.h"
23 * context to signal a cond
25 * Generic context to signal a cond and store the return value. We
26 * assume the caller is holding the appropriate lock.
28 class C_Cond
: public Context
{
29 Cond
*cond
; ///< Cond to signal
30 bool *done
; ///< true if finish() has been called
31 int *rval
; ///< return value
33 C_Cond(Cond
*c
, bool *d
, int *r
) : cond(c
), done(d
), rval(r
) {
36 void finish(int r
) override
{
44 * context to signal a cond, protected by a lock
46 * Generic context to signal a cond under a specific lock. We take the
47 * lock in the finish() callback, so the finish() caller must not
50 class C_SafeCond
: public Context
{
51 Mutex
*lock
; ///< Mutex to take
52 Cond
*cond
; ///< Cond to signal
53 bool *done
; ///< true after finish() has been called
54 int *rval
; ///< return value (optional)
56 C_SafeCond(Mutex
*l
, Cond
*c
, bool *d
, int *r
=0) : lock(l
), cond(c
), done(d
), rval(r
) {
59 void finish(int r
) override
{
70 * Context providing a simple wait() mechanism to wait for completion
72 * The context will not be deleted as part of complete and must live
73 * until wait() returns.
75 class C_SaferCond
: public Context
{
76 Mutex lock
; ///< Mutex to take
77 Cond cond
; ///< Cond to signal
78 bool done
; ///< true after finish() has been called
79 int rval
; ///< return value
81 C_SaferCond() : lock("C_SaferCond"), done(false), rval(0) {}
82 void finish(int r
) override
{ complete(r
); }
84 /// We overload complete in order to not delete the context
85 void complete(int r
) override
{
86 Mutex::Locker
l(lock
);
92 /// Returns rval once the Context is called
94 Mutex::Locker
l(lock
);