#include <memory>
#include "include/ceph_assert.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
#define mydout(cct, v) lgeneric_subdout(cct, context, v)
class C_GatherBase {
private:
CephContext *cct;
- int result;
+ int result = 0;
ContextType *onfinish;
#ifdef DEBUG_GATHER
std::set<ContextType*> waitfor;
#endif
- int sub_created_count;
- int sub_existing_count;
- mutable Mutex lock;
- bool activated;
+ int sub_created_count = 0;
+ int sub_existing_count = 0;
+ mutable ceph::recursive_mutex lock =
+ ceph::make_recursive_mutex("C_GatherBase::lock"); // disable lockdep
+ bool activated = false;
void sub_finish(ContextType* sub, int r) {
- lock.Lock();
+ lock.lock();
#ifdef DEBUG_GATHER
ceph_assert(waitfor.count(sub));
waitfor.erase(sub);
if (r < 0 && result == 0)
result = r;
if ((activated == false) || (sub_existing_count != 0)) {
- lock.Unlock();
+ lock.unlock();
return;
}
- lock.Unlock();
+ lock.unlock();
delete_me();
}
public:
C_GatherBase(CephContext *cct_, ContextType *onfinish_)
- : cct(cct_), result(0), onfinish(onfinish_),
- sub_created_count(0), sub_existing_count(0),
- lock("C_GatherBase::lock", true, false), //disable lockdep
- activated(false)
+ : cct(cct_), onfinish(onfinish_)
{
mydout(cct,10) << "C_GatherBase " << this << ".new" << dendl;
}
mydout(cct,10) << "C_GatherBase " << this << ".delete" << dendl;
}
void set_finisher(ContextType *onfinish_) {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
ceph_assert(!onfinish);
onfinish = onfinish_;
}
void activate() {
- lock.Lock();
+ lock.lock();
ceph_assert(activated == false);
activated = true;
if (sub_existing_count != 0) {
- lock.Unlock();
+ lock.unlock();
return;
}
- lock.Unlock();
+ lock.unlock();
delete_me();
}
ContextType *new_sub() {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
ceph_assert(activated == false);
sub_created_count++;
sub_existing_count++;
}
inline int get_sub_existing_count() const {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
return sub_existing_count;
}
inline int get_sub_created_count() const {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
return sub_created_count;
}
};