]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
AsyncConnection: Avoid hungry if mark_down's caller is the eventcenter's owner
authorHaomai Wang <haomaiwang@gmail.com>
Fri, 5 Dec 2014 18:18:36 +0000 (02:18 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Sat, 6 Dec 2014 16:33:39 +0000 (00:33 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/msg/async/AsyncConnection.h
src/msg/async/AsyncMessenger.cc
src/msg/async/Event.cc
src/msg/async/Event.h

index ac1e3e3f5593095d0a1a78222a3c1967744a4877..5ccd7904c7fa2030de8165d26000959fe4a0dec1 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef CEPH_MSG_ASYNCCONNECTION_H
 #define CEPH_MSG_ASYNCCONNECTION_H
 
+#include <pthread.h>
 #include <list>
 #include <map>
 using namespace std;
@@ -140,11 +141,16 @@ class AsyncConnection : public Connection {
   //  \                                         signal
   // finished
   //
-  // Note: Don't call it from AsyncConnection
+  // The above flow only happen when the caller isn't the pthread own center,
+  // if the owner of center is self, it's safe to call _stop() directly;
   void mark_down() {
     Mutex::Locker l(stop_lock);
-    center->dispatch_event_external(stop_handler);
-    stop_cond.Wait(stop_lock);
+    if (center->get_owner() == pthread_self()) {
+      _stop();
+    } else {
+      center->dispatch_event_external(stop_handler);
+      stop_cond.Wait(stop_lock);
+    }
   }
   void mark_disposable() {
     Mutex::Locker l(lock);
index 03afc0adeb269769ab98afa7492721c12fd680df..032538aa6985f4bacfa61e439859da5dc158e0c3 100644 (file)
@@ -293,6 +293,7 @@ void *Worker::entry()
   ldout(cct, 10) << __func__ << " starting" << dendl;
   int r;
 
+  center.set_owner(pthread_self());
   while (!done) {
     ldout(cct, 20) << __func__ << " calling event process" << dendl;
 
index 6d2960f8a26c8fb6159049d336c45d9a7e30a900..15dccbee8d1db57f19e75667567f5f52a950cd85 100644 (file)
@@ -248,6 +248,8 @@ int EventCenter::process_time_events()
 
 int EventCenter::process_events(int timeout_microseconds)
 {
+  // Must set owner before looping
+  assert(owner);
   struct timeval tv;
   int numevents;
   bool trigger_time = false;
index 50ae7553a540ac64c01a425e8d809838e407f0da..a35c9fe9ecb3bd4e97f5c5e9a13d56e96f31599f 100644 (file)
@@ -37,6 +37,8 @@
 #endif
 #endif
 
+#include <pthread.h>
+
 #include "include/Context.h"
 #include "include/unordered_map.h"
 #include "common/WorkQueue.h"
@@ -112,6 +114,7 @@ class EventCenter {
   int notify_receive_fd;
   int notify_send_fd;
   NetHandler net;
+  pthread_t owner;
 
   int process_time_events();
   FileEvent *_get_file_event(int fd) {
@@ -126,11 +129,14 @@ class EventCenter {
     cct(c), nevent(0),
     lock("AsyncMessenger::lock"),
     driver(NULL), time_event_next_id(0),
-    notify_receive_fd(-1), notify_send_fd(-1), net(c) {
+    notify_receive_fd(-1), notify_send_fd(-1), net(c), owner(0) {
     last_time = time(NULL);
   }
   ~EventCenter();
   int init(int nevent);
+  void set_owner(pthread_t p) { owner = p; }
+  pthread_t get_owner() { return owner; }
+
   // Used by internal thread
   int create_file_event(int fd, int mask, EventCallbackRef ctxt);
   uint64_t create_time_event(uint64_t milliseconds, EventCallbackRef ctxt);