]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
PipeConnection: Avoid deadlock when calling is_connected
authorHaomai Wang <haomaiwang@gmail.com>
Sun, 7 Dec 2014 04:27:38 +0000 (12:27 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Thu, 18 Dec 2014 14:51:33 +0000 (22:51 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/msg/Connection.h
src/msg/simple/PipeConnection.cc
src/msg/simple/SimpleMessenger.cc
src/msg/simple/SimpleMessenger.h

index 7ff0beb9662aab6564823013ef94f655266ca5c1..8961d6438f5071a8dc467f7b71009d897e5754ea 100644 (file)
@@ -92,6 +92,13 @@ public:
     return NULL;
   }
 
+  /**
+   * Used to judge whether this connection is ready to send. Usually, the
+   * implementation need to build a own shakehand or sesson then it can be
+   * ready to send.
+   *
+   * @return true if ready to send, or false otherwise
+   */
   virtual bool is_connected() = 0;
 
   Messenger *get_messenger() {
index cd20d9774a9829f1ebacaa7c99a863c62b521357..96e27a4fd301fb791c85f451a6dff2b49d25b1d5 100644 (file)
@@ -67,11 +67,9 @@ void PipeConnection::reset_pipe(Pipe *p)
   pipe = p->get();
 }
 
-bool PipeConnection::is_connected() {
-  Mutex::Locker l(lock);
-  if (pipe)
-    return pipe->is_connected();
-  return false;
+bool PipeConnection::is_connected()
+{
+  return static_cast<SimpleMessenger*>(msgr)->is_connected(this);
 }
 
 int PipeConnection::send_message(Message *m)
index edc8f0fe598a78ddaa1deb0c722edb6aa301293f..38b5d846a2cc7dc563e5bbc31cc722032cf0f8b3 100644 (file)
@@ -266,7 +266,19 @@ void SimpleMessenger::queue_reap(Pipe *pipe)
   lock.Unlock();
 }
 
-
+bool SimpleMessenger::is_connected(Connection *con)
+{
+  bool r = false;
+  if (con) {
+    Pipe *p = static_cast<Pipe *>(static_cast<PipeConnection*>(con)->get_pipe());
+    if (p) {
+      assert(p->msgr == this);
+      r = p->is_connected();
+      p->put();
+    }
+  }
+  return r;
+}
 
 int SimpleMessenger::bind(const entity_addr_t &bind_addr)
 {
index bb63dbe93cf39f38ba3b183ab5160026ace731ff..7581178f0a5fd260be7bbbfaf58c682be844b55e 100644 (file)
@@ -409,6 +409,11 @@ public:
    * ready to be torn down.
    */
   void queue_reap(Pipe *pipe);
+
+  /**
+   * Used to get whether this connection ready to send
+   */
+  bool is_connected(Connection *con);
   /**
    * @} // SimpleMessenger Internals
    */