From: Noah Watkins Date: Sat, 12 Oct 2013 21:39:19 +0000 (-0700) Subject: ceph_context: use condition variable for wake-up X-Git-Tag: v0.73~66^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c7d975aeadf908d11577c480fa0a2e831d069c55;p=ceph.git ceph_context: use condition variable for wake-up reopen_logs is called from normal thread context (as opposed to an async signal handler), so we grab a mutex and condition variables. The mutex use also allows us to avoid volatile variables since the mutex will add any necessary barriers. Signed-off-by: Noah Watkins --- diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index e694a2f09b39..4382dbf69af2 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -27,10 +27,11 @@ #include "log/Log.h" #include "auth/Crypto.h" #include "include/str_list.h" +#include "common/Mutex.h" +#include "common/Cond.h" #include #include -#include using ceph::HeartbeatMap; @@ -38,30 +39,28 @@ class CephContextServiceThread : public Thread { public: CephContextServiceThread(CephContext *cct) - : _reopen_logs(false), _exit_thread(false), _cct(cct) + : _lock("CephContextServiceThread::_lock"), + _reopen_logs(false), _exit_thread(false), _cct(cct) { - sem_init(&_sem, 0, 0); - }; + } - ~CephContextServiceThread() - { - sem_destroy(&_sem); - }; + ~CephContextServiceThread() {} void *entry() { while (1) { + Mutex::Locker l(_lock); + if (_cct->_conf->heartbeat_interval) { - struct timespec timeout; - clock_gettime(CLOCK_REALTIME, &timeout); - timeout.tv_sec += _cct->_conf->heartbeat_interval; - sem_timedwait(&_sem, &timeout); - } else { - sem_wait(&_sem); - } + utime_t interval(_cct->_conf->heartbeat_interval, 0); + _cond.WaitInterval(_cct, _lock, interval); + } else + _cond.Wait(_lock); + if (_exit_thread) { break; } + if (_reopen_logs) { _cct->_log->reopen_log_file(); _reopen_logs = false; @@ -73,20 +72,23 @@ public: void reopen_logs() { + Mutex::Locker l(_lock); _reopen_logs = true; - sem_post(&_sem); + _cond.Signal(); } void exit_thread() { + Mutex::Locker l(_lock); _exit_thread = true; - sem_post(&_sem); + _cond.Signal(); } private: - volatile bool _reopen_logs; - volatile bool _exit_thread; - sem_t _sem; + Mutex _lock; + Cond _cond; + bool _reopen_logs; + bool _exit_thread; CephContext *_cct; };