]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msgr: make connection pipe reset atomic
authorSage Weil <sage@newdream.net>
Mon, 24 Jan 2011 18:59:21 +0000 (10:59 -0800)
committerSage Weil <sage@newdream.net>
Mon, 24 Jan 2011 18:59:42 +0000 (10:59 -0800)
Close a small and unlikely race.

Signed-off-by: Sage Weil <sage@newdream.net>
src/msg/Message.h
src/msg/SimpleMessenger.cc

index 8e054d6a127168cca789ec690523339fa30ab2f7..d161cb4033422b0d7b15d8a63915c4a6c3cf7e26 100644 (file)
@@ -212,6 +212,12 @@ public:
       pipe = NULL;
     }
   }
+  void reset_pipe(RefCountedObject *p) {
+    Mutex::Locker l(lock);
+    if (pipe)
+      pipe->put();
+    pipe = p->get();
+  }
 
   int get_peer_type() { return peer_type; }
   void set_peer_type(int t) { peer_type = t; }
index eb902bb048e9a26b232be361cfc32b8d3b80cbe3..5f8f89929b960a3ec758d795651a49fff7b74dd9 100644 (file)
@@ -876,8 +876,7 @@ int SimpleMessenger::Pipe::accept()
   if (!existing->policy.lossy) { /* if we're lossy, we can lose messages and
                                     should let the daemon handle it itself.
     Otherwise, take over other Connection so we don't lose older messages */
-    existing->connection_state->clear_pipe();
-    existing->connection_state->pipe = get();
+    existing->connection_state->reset_pipe(this);
     existing->connection_state->put();
     existing->connection_state = NULL;