#include "common/version.h"
#include "common/dout.h"
#include "common/debug.h"
-#include "common/Cond.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
#include "common/Timer.h"
#include "common/errno.h"
#include "mon/MonClient.h"
Messenger *msg;
MonClient monc;
- Mutex lock;
+ ceph::mutex lock = ceph::make_mutex("mon-msg-test::lock");
set<int> wanted;
: Dispatcher(cct_),
cct(cct_),
msg(NULL),
- monc(cct_),
- lock("mon-msg-test::lock")
+ monc(cct_)
{ }
protected:
int reply_type = 0;
Message *reply_msg = nullptr;
- Mutex lock;
- Cond cond;
+ ceph::mutex lock = ceph::make_mutex("lock");
+ ceph::condition_variable cond;
MonMsgTest() :
- MonClientHelper(g_ceph_context),
- lock("lock") { }
+ MonClientHelper(g_ceph_context) { }
public:
void SetUp() override {
}
void handle_wanted(Message *m) override {
- lock.Lock();
+ std::lock_guard l{lock};
// caller will put() after they call us, so hold on to a ref
m->get();
reply_msg = m;
- cond.Signal();
- lock.Unlock();
+ cond.notify_all();
}
Message *send_wait_reply(Message *m, int t, double timeout=30.0) {
- lock.Lock();
+ std::unique_lock l{lock};
reply_type = t;
add_wanted(t);
send_message(m);
- int err = 0;
+ std::cv_status status = std::cv_status::no_timeout;
if (timeout > 0) {
- utime_t cond_timeout;
- cond_timeout.set_from_double(timeout);
utime_t s = ceph_clock_now();
- err = cond.WaitInterval(lock, cond_timeout);
+ status = cond.wait_for(l, ceph::make_timespan(timeout));
utime_t e = ceph_clock_now();
dout(20) << __func__ << " took " << (e-s) << " seconds" << dendl;
} else {
- err = cond.Wait(lock);
+ cond.wait(l);
}
rm_wanted(t);
- lock.Unlock();
- if (err > 0) {
- dout(20) << __func__ << " error: " << cpp_strerror(err) << dendl;
- return (Message*)((long)-err);
+ l.unlock();
+ if (status == std::cv_status::timeout) {
+ dout(20) << __func__ << " error: " << cpp_strerror(ETIMEDOUT) << dendl;
+ return (Message*)((long)-ETIMEDOUT);
}
if (!reply_msg)
#include "common/config.h"
#include "common/debug.h"
#include "common/errno.h"
-#include "common/Cond.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
#include "common/strtol.h"
#include "common/LogEntry.h"
#include "auth/KeyRing.h"
MessengerRef messenger;
MonClient monc;
- Mutex lock;
- Cond cond;
+ ceph::mutex lock;
+ ceph::condition_variable cond;
SafeTimer timer;
bool do_shutdown;
virtual int init() = 0;
virtual int shutdown() {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
do_shutdown = true;
int r = _shutdown();
if (r < 0) {
TestStub(CephContext *cct, string who)
: Dispatcher(cct),
monc(cct),
- lock(who.append("::lock").c_str()),
+ lock(ceph::make_mutex(who.append("::lock"))),
timer(cct, lock),
do_shutdown(false),
tick_seconds(0.0) { }
protected:
bool ms_dispatch(Message *m) override {
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
dout(1) << "client::" << __func__ << " " << *m << dendl;
switch (m->get_type()) {
case CEPH_MSG_OSD_MAP:
objecter->handle_osd_map((MOSDMap*)m);
- cond.Signal();
+ cond.notify_all();
break;
}
return true;
void ms_handle_connect(Connection *con) override {
dout(1) << "client::" << __func__ << " " << con << dendl;
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
objecter->ms_handle_connect(con);
}
void ms_handle_remote_reset(Connection *con) override {
dout(1) << "client::" << __func__ << " " << con << dendl;
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
objecter->ms_handle_remote_reset(con);
}
bool ms_handle_reset(Connection *con) override {
dout(1) << "client::" << __func__ << dendl;
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
objecter->ms_handle_reset(con);
return false;
}
objecter->set_client_incarnation(0);
objecter->start();
- lock.Lock();
+ lock.lock();
timer.init();
monc.renew_subs();
- lock.Unlock();
+ lock.unlock();
objecter->wait_for_osd_map();
int init() override {
dout(10) << __func__ << dendl;
- Mutex::Locker l(lock);
+ std::lock_guard l{lock};
dout(1) << __func__ << " fsid " << monc.monmap.fsid
<< " osd_fsid " << g_conf()->osd_uuid << dendl;
const char *our_name = NULL;
vector<TestStub*> stubs;
-Mutex shutdown_lock("main::shutdown_lock");
-Cond shutdown_cond;
+ceph::mutex shutdown_lock = ceph::make_mutex("main::shutdown_lock");
+ceph::condition_variable shutdown_cond;
Context *shutdown_cb = NULL;
SafeTimer *shutdown_timer = NULL;
{
void finish(int r) override {
generic_dout(10) << "main::shutdown time has ran out" << dendl;
- shutdown_cond.Signal();
+ shutdown_cond.notify_all();
}
};
return;
std::cerr << "*** Got signal " << sig_str(signum) << " ***" << std::endl;
- Mutex::Locker l(shutdown_lock);
+ std::lock_guard l{shutdown_lock};
if (shutdown_timer) {
shutdown_timer->cancel_all_events();
- shutdown_cond.Signal();
+ shutdown_cond.notify_all();
}
}
register_async_signal_handler_oneshot(SIGINT, handle_test_signal);
register_async_signal_handler_oneshot(SIGTERM, handle_test_signal);
- shutdown_lock.Lock();
- shutdown_timer = new SafeTimer(g_ceph_context, shutdown_lock);
- shutdown_timer->init();
- if (duration != 0) {
- std::cout << __func__
- << " run test for " << duration << " seconds" << std::endl;
- shutdown_timer->add_event_after((double) duration, new C_Shutdown);
+ {
+ unique_lock locker{shutdown_lock};
+ shutdown_timer = new SafeTimer(g_ceph_context, shutdown_lock);
+ shutdown_timer->init();
+ if (duration != 0) {
+ std::cout << __func__
+ << " run test for " << duration << " seconds" << std::endl;
+ shutdown_timer->add_event_after((double) duration, new C_Shutdown);
+ }
+ shutdown_cond.wait(locker);
+ shutdown_timer->shutdown();
+ delete shutdown_timer;
+ shutdown_timer = NULL;
}
- shutdown_cond.Wait(shutdown_lock);
-
- shutdown_timer->shutdown();
- delete shutdown_timer;
- shutdown_timer = NULL;
- shutdown_lock.Unlock();
-
unregister_async_signal_handler(SIGINT, handle_test_signal);
unregister_async_signal_handler(SIGTERM, handle_test_signal);