#ifndef CEPH_MSG_ASYNCCONNECTION_H
#define CEPH_MSG_ASYNCCONNECTION_H
+#include <pthread.h>
#include <list>
#include <map>
using namespace std;
// \ 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);
ldout(cct, 10) << __func__ << " starting" << dendl;
int r;
+ center.set_owner(pthread_self());
while (!done) {
ldout(cct, 20) << __func__ << " calling event process" << dendl;
#endif
#endif
+#include <pthread.h>
+
#include "include/Context.h"
#include "include/unordered_map.h"
#include "common/WorkQueue.h"
int notify_receive_fd;
int notify_send_fd;
NetHandler net;
+ pthread_t owner;
int process_time_events();
FileEvent *_get_file_event(int fd) {
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);