};
private:
- Mutex lock;
+ ceph::mutex lock = ceph::make_mutex("PausyAsyncMap");
map<string, bufferlist> store;
class Doer : public Thread {
static const size_t MAX_SIZE = 100;
PausyAsyncMap *parent;
- Mutex lock;
- Cond cond;
+ ceph::mutex lock = ceph::make_mutex("Doer lock");
+ ceph::condition_variable cond;
int stopping;
bool paused;
list<Op> queue;
public:
explicit Doer(PausyAsyncMap *parent) :
- parent(parent), lock("Doer lock"), stopping(0), paused(false) {}
+ parent(parent), stopping(0), paused(false) {}
void *entry() override {
while (1) {
list<Op> ops;
{
- Mutex::Locker l(lock);
- while (!stopping && (queue.empty() || paused))
- cond.Wait(lock);
+ std::unique_lock l{lock};
+ cond.wait(l, [this] {
+ return stopping || (!queue.empty() && !paused);
+ });
if (stopping && queue.empty()) {
stopping = 2;
- cond.Signal();
+ cond.notify_all();
return 0;
}
ceph_assert(!queue.empty());
ceph_assert(!paused);
ops.swap(queue);
- cond.Signal();
+ cond.notify_all();
}
ceph_assert(!ops.empty());
ops.erase(i++)) {
if (!(rand()%3))
usleep(1+(rand() % 5000));
- Mutex::Locker l(parent->lock);
+ std::lock_guard l{parent->lock};
(*i)->operate(&(parent->store));
}
}
}
void pause() {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
paused = true;
- cond.Signal();
+ cond.notify_all();
}
void resume() {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
paused = false;
- cond.Signal();
+ cond.notify_all();
}
void submit(list<Op> &in) {
- Mutex::Locker l(lock);
- while (queue.size() >= MAX_SIZE)
- cond.Wait(lock);
+ std::unique_lock l{lock};
+ cond.wait(l, [this] { return queue.size() < MAX_SIZE;});
queue.splice(queue.end(), in, in.begin(), in.end());
- cond.Signal();
+ cond.notify_all();
}
void stop() {
- Mutex::Locker l(lock);
+ std::unique_lock l{lock};
stopping = 1;
- cond.Signal();
- while (stopping != 2)
- cond.Wait(lock);
- cond.Signal();
+ cond.notify_all();
+ cond.wait(l, [this] { return stopping == 2; });
+ cond.notify_all();
}
} doer;
public:
- PausyAsyncMap() : lock("PausyAsyncMap"), doer(this) {
+ PausyAsyncMap() : doer(this) {
doer.create("doer");
}
~PausyAsyncMap() override {
int get_keys(
const set<string> &keys,
map<string, bufferlist> *out) override {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
for (set<string>::const_iterator i = keys.begin();
i != keys.end();
++i) {
int get_next(
const string &key,
pair<string, bufferlist> *next) override {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
map<string, bufferlist>::iterator j = store.upper_bound(key);
if (j != store.end()) {
if (next)
}
void flush() {
- Mutex lock("flush lock");
- Cond cond;
+ ceph::mutex lock = ceph::make_mutex("flush lock");
+ ceph::condition_variable cond;
bool done = false;
class OnFinish : public Context {
- Mutex *lock;
- Cond *cond;
+ ceph::mutex *lock;
+ ceph::condition_variable *cond;
bool *done;
public:
- OnFinish(Mutex *lock, Cond *cond, bool *done)
+ OnFinish(ceph::mutex *lock, ceph::condition_variable *cond, bool *done)
: lock(lock), cond(cond), done(done) {}
void finish(int) override {
- Mutex::Locker l(*lock);
+ std::lock_guard l{*lock};
*done = true;
- cond->Signal();
+ cond->notify_all();
}
};
Transaction t;
t.add_callback(new OnFinish(&lock, &cond, &done));
submit(&t);
{
- Mutex::Locker l(lock);
- while (!done)
- cond.Wait(lock);
+ std::unique_lock l{lock};
+ cond.wait(l, [&] { return done; });
}
}
snapid_t next;
uint32_t mask;
uint32_t bits;
- Mutex lock;
+ ceph::mutex lock = ceph::make_mutex("lock");
public:
MapperVerifier(
uint32_t bits)
: driver(driver),
mapper(new SnapMapper(g_ceph_context, driver, mask, bits, 0, shard_id_t(1))),
- mask(mask), bits(bits),
- lock("lock") {}
+ mask(mask), bits(bits) {}
hobject_t random_hobject() {
return hobject_t(
}
void create_object() {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
if (snap_to_hobject.empty())
return;
hobject_t obj;
}
void trim_snap() {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
if (snap_to_hobject.empty())
return;
map<snapid_t, set<hobject_t> >::iterator snap =
}
void remove_oid() {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
if (hobject_to_snap.empty())
return;
map<hobject_t, set<snapid_t>>::iterator obj =
}
void check_oid() {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
if (hobject_to_snap.empty())
return;
map<hobject_t, set<snapid_t>>::iterator obj =