]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: swap state spinlock for atomic_t 2613/head
authorSage Weil <sage@redhat.com>
Tue, 30 Sep 2014 18:56:30 +0000 (11:56 -0700)
committerSage Weil <sage@redhat.com>
Tue, 30 Sep 2014 18:56:30 +0000 (11:56 -0700)
We are hitting a strange issue with valgrind and pthread spinlocks. Avoid
the issue by using an atomic_t here (which is simpler anyway).

Avoids: #8822
Backport: firefly
Signed-off-by: Sage Weil <sage@redhat.com>
src/osd/OSD.cc
src/osd/OSD.h

index 4e735b085f8ddf29ad47242d25b4daadfa1dde70..a53dfca4859ca27aba6592a4d14feb05d49456a1 100644 (file)
@@ -1642,7 +1642,7 @@ OSD::OSD(CephContext *cct_, ObjectStore *store_,
   dispatch_running(false),
   asok_hook(NULL),
   osd_compat(get_osd_compat_set()),
-  state_lock(), state(STATE_INITIALIZING),
+  state(STATE_INITIALIZING),
   osd_tp(cct, "OSD::osd_tp", cct->_conf->osd_op_threads, "osd_op_threads"),
   osd_op_tp(cct, "OSD::osd_op_tp", 
     cct->_conf->osd_op_num_threads_per_shard * cct->_conf->osd_op_num_shards),
index 8ad18e3b09631490ca356c6567f29060c84c3618..426a2b1fab7019e3d91ffc76b5f5b8fd1bb84092 100644 (file)
@@ -1050,37 +1050,29 @@ public:
   }
 
 private:
-  Spinlock state_lock; // protects access to state
-  int state;
+  atomic_t state;
 
 public:
   int get_state() {
-    Spinlock::Locker l(state_lock);
-    return state;
+    return state.read();
   }
   void set_state(int s) {
-    Spinlock::Locker l(state_lock);
-    state = s;
+    state.set(s);
   }
   bool is_initializing() {
-    Spinlock::Locker l(state_lock);
-    return state == STATE_INITIALIZING;
+    return get_state() == STATE_INITIALIZING;
   }
   bool is_booting() {
-    Spinlock::Locker l(state_lock);
-    return state == STATE_BOOTING;
+    return get_state() == STATE_BOOTING;
   }
   bool is_active() {
-    Spinlock::Locker l(state_lock);
-    return state == STATE_ACTIVE;
+    return get_state() == STATE_ACTIVE;
   }
   bool is_stopping() {
-    Spinlock::Locker l(state_lock);
-    return state == STATE_STOPPING;
+    return get_state() == STATE_STOPPING;
   }
   bool is_waiting_for_healthy() {
-    Spinlock::Locker l(state_lock);
-    return state == STATE_WAITING_FOR_HEALTHY;
+    return get_state() == STATE_WAITING_FOR_HEALTHY;
   }
 
 private: