]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_context: use condition variable for wake-up 771/head
authorNoah Watkins <noahwatkins@gmail.com>
Sat, 12 Oct 2013 21:39:19 +0000 (14:39 -0700)
committerNoah Watkins <noahwatkins@gmail.com>
Mon, 28 Oct 2013 20:04:29 +0000 (13:04 -0700)
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 <noahwatkins@gmail.com>
src/common/ceph_context.cc

index e694a2f09b393a7b2583e85de9efa108032cbd5e..4382dbf69af2d08ad6f41280278cfbd7020d20c1 100644 (file)
 #include "log/Log.h"
 #include "auth/Crypto.h"
 #include "include/str_list.h"
+#include "common/Mutex.h"
+#include "common/Cond.h"
 
 #include <iostream>
 #include <pthread.h>
-#include <semaphore.h>
 
 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;
 };