Skip to content

Commit

Permalink
msg/async/Event: change to use pthread_t to indicate whether the same…
Browse files Browse the repository at this point in the history
… thread

thread_local has problem in TmapMigratePP.DataScan case that it will be
assigned to zero unexpectedly.

pthread_t is much cheaper than gettid since it's a library implementation.

Signed-off-by: Haomai Wang <haomai@xsky.com>
  • Loading branch information
yuyuyu101 committed Jun 28, 2016
1 parent b9cc756 commit 31cbae2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/msg/async/Event.cc
Expand Up @@ -59,8 +59,6 @@ ostream& EventCenter::_event_prefix(std::ostream *_dout)
<< " time_id=" << time_event_next_id << ").";
}

thread_local EventCenter* local_center = nullptr;

int EventCenter::init(int n, unsigned i)
{
// can't init multi times
Expand Down Expand Up @@ -145,8 +143,9 @@ void EventCenter::set_owner()
cct->lookup_or_create_singleton_object<EventCenter::AssociatedCenters>(
global_centers, "AsyncMessenger::EventCenter::global_center");
assert(global_centers && !global_centers->centers[idx]);
global_centers->centers[idx] = local_center = this;
ldout(cct, 1) << __func__ << " idx=" << idx << " local_center=" << local_center << dendl;
global_centers->centers[idx] = this;
owner = pthread_self();
ldout(cct, 1) << __func__ << " idx=" << idx << " owner=" << owner << dendl;
}

int EventCenter::create_file_event(int fd, int mask, EventCallbackRef ctxt)
Expand Down
9 changes: 2 additions & 7 deletions src/msg/async/Event.h
Expand Up @@ -80,12 +80,6 @@ class EventDriver {
virtual int resize_events(int newsize) = 0;
};

extern thread_local EventCenter* local_center;

inline EventCenter* center() {
return local_center;
}

/*
* EventCenter maintain a set of file descriptor and handle registered events.
*/
Expand Down Expand Up @@ -119,6 +113,7 @@ class EventCenter {
CephContext *cct;
int nevent;
// Used only to external event
pthread_t owner;
std::mutex external_lock, file_lock;;
std::atomic_ulong external_num_events;
deque<EventCallbackRef> external_events;
Expand Down Expand Up @@ -169,7 +164,7 @@ class EventCenter {
// Used by external thread
void dispatch_event_external(EventCallbackRef e);
inline bool in_thread() const {
return local_center == this;
return pthread_equal(pthread_self(), owner);
}

private:
Expand Down

0 comments on commit 31cbae2

Please sign in to comment.