Created
August 14, 2010 17:35
-
-
Save stanaka/524517 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -u libevent-1.4.14b-stable.orig/event.c libevent-1.4.14b-stable/event.c | |
--- libevent-1.4.14b-stable.orig/event.c 2010-06-20 22:06:04.000000000 +0900 | |
+++ libevent-1.4.14b-stable/event.c 2010-08-15 02:34:35.000000000 +0900 | |
@@ -50,6 +50,7 @@ | |
#include <string.h> | |
#include <assert.h> | |
#include <time.h> | |
+#include <pthread.h> | |
#include "event.h" | |
#include "event-internal.h" | |
@@ -109,6 +110,8 @@ | |
extern struct event_base *evsignal_base; | |
static int use_monotonic; | |
+pthread_mutex_t mutex; | |
+ | |
/* Handle signals - This is a deprecated interface */ | |
int (*event_sigcb)(void); /* Signal callback when gotsig is set */ | |
volatile sig_atomic_t event_gotsig; /* Set in signal handler */ | |
@@ -163,6 +166,7 @@ | |
event_init(void) | |
{ | |
struct event_base *base = event_base_new(); | |
+ pthread_mutex_init(&mutex, NULL); | |
if (base != NULL) | |
current_base = base; | |
@@ -380,6 +384,7 @@ | |
assert(activeq != NULL); | |
+ pthread_mutex_lock(&mutex); | |
for (ev = TAILQ_FIRST(activeq); ev; ev = TAILQ_FIRST(activeq)) { | |
if (ev->ev_events & EV_PERSIST) | |
event_queue_remove(base, ev, EVLIST_ACTIVE); | |
@@ -397,6 +402,7 @@ | |
return; | |
} | |
} | |
+ pthread_mutex_unlock(&mutex); | |
} | |
/* | |
@@ -954,7 +960,7 @@ | |
ev, ev->ev_fd, queue); | |
if (~ev->ev_flags & EVLIST_INTERNAL) | |
- base->event_count--; | |
+ __sync_sub_and_fetch(&(base->event_count), 1); | |
ev->ev_flags &= ~queue; | |
switch (queue) { | |
@@ -962,7 +968,7 @@ | |
TAILQ_REMOVE(&base->eventqueue, ev, ev_next); | |
break; | |
case EVLIST_ACTIVE: | |
- base->event_count_active--; | |
+ __sync_sub_and_fetch(&(base->event_count_active), 1); | |
TAILQ_REMOVE(base->activequeues[ev->ev_pri], | |
ev, ev_active_next); | |
break; | |
@@ -987,7 +993,7 @@ | |
} | |
if (~ev->ev_flags & EVLIST_INTERNAL) | |
- base->event_count++; | |
+ __sync_add_and_fetch(&(base->event_count), 1); | |
ev->ev_flags |= queue; | |
switch (queue) { | |
@@ -995,7 +1001,7 @@ | |
TAILQ_INSERT_TAIL(&base->eventqueue, ev, ev_next); | |
break; | |
case EVLIST_ACTIVE: | |
- base->event_count_active++; | |
+ __sync_add_and_fetch(&(base->event_count_active), 1); | |
TAILQ_INSERT_TAIL(base->activequeues[ev->ev_pri], | |
ev,ev_active_next); | |
break; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment