diff options
author | Sergey Matveychuk <sem@FreeBSD.org> | 2007-02-06 16:25:27 +0000 |
---|---|---|
committer | Sergey Matveychuk <sem@FreeBSD.org> | 2007-02-06 16:25:27 +0000 |
commit | 14f229309b605af6427393b11fd28207f3aca5ce (patch) | |
tree | 55553b618e24d755dda930ee37b1567834ad1759 /devel/libpdel | |
parent | b1b8e42b9144366f714d52ca620f48f25f759703 (diff) |
Notes
Diffstat (limited to 'devel/libpdel')
-rw-r--r-- | devel/libpdel/Makefile | 2 | ||||
-rw-r--r-- | devel/libpdel/files/patch-util_paction.c | 54 | ||||
-rw-r--r-- | devel/libpdel/files/patch-util_pevent.c | 107 |
3 files changed, 162 insertions, 1 deletions
diff --git a/devel/libpdel/Makefile b/devel/libpdel/Makefile index 12a1a727d1a7..1f445a461f96 100644 --- a/devel/libpdel/Makefile +++ b/devel/libpdel/Makefile @@ -7,7 +7,7 @@ PORTNAME= libpdel PORTVERSION= 0.5.3 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= devel net www MASTER_SITES= LOCAL/archie diff --git a/devel/libpdel/files/patch-util_paction.c b/devel/libpdel/files/patch-util_paction.c new file mode 100644 index 000000000000..d88c55a9ffc9 --- /dev/null +++ b/devel/libpdel/files/patch-util_paction.c @@ -0,0 +1,54 @@ +--- util/paction.c (revision 68) ++++ util/paction.c (working copy) +@@ -39,7 +39,7 @@ + #endif + paction_finish_t *finish; /* action finisher */ + void *arg; /* action argument */ +- u_char started; /* action thread started */ ++ u_char may_cancel; /* ok to cancel action thread */ + u_char canceled; /* action was canceled */ + }; + +@@ -118,10 +118,11 @@ + + /* + * Don't cancel the thread before paction_main() starts, because +- * then paction_cleanup() would never get invoked. Instead, use +- * the 'started' and 'canceled' flags to avoid this race condition. ++ * then paction_cleanup() would never get invoked. Also don't ++ * pthread_cancel() the thread after the handler has completed, ++ * because we might cancel in the middle of the cleanup. + */ +- if (action->started) ++ if (action->may_cancel) + pthread_cancel(action->tid); + + /* Unlock action */ +@@ -139,9 +140,9 @@ + /* Cleanup when thread exits */ + pthread_cleanup_push(paction_cleanup, action); + +- /* Mark thread as started */ +- assert(!action->started); +- action->started = 1; /* race condition ok */ ++ /* Begin allowing pthread_cancel()'s */ ++ assert(!action->may_cancel); ++ action->may_cancel = 1; + + /* Handle race between paction_cancel() and paction_main() */ + if (action->canceled) /* race condition ok */ +@@ -151,6 +152,14 @@ + (*action->handler)(action->arg); + + done:; ++ /* Stop allowing pthread_cancel()'s */ ++ MUTEX_LOCK(&action->mutex, action->mutex_count); ++ action->may_cancel = 0; ++ MUTEX_UNLOCK(&action->mutex, action->mutex_count); ++ ++ /* Consume any last-minute pthread_cancel() still pending */ ++ pthread_testcancel(); ++ + /* Done */ + pthread_cleanup_pop(1); + return (NULL); diff --git a/devel/libpdel/files/patch-util_pevent.c b/devel/libpdel/files/patch-util_pevent.c new file mode 100644 index 000000000000..661ce558f5cc --- /dev/null +++ b/devel/libpdel/files/patch-util_pevent.c @@ -0,0 +1,107 @@ +--- util/pevent.c 2005/09/10 20:19:46 972 ++++ util/pevent.c 2006/10/07 23:59:17 980 +@@ -122,6 +122,15 @@ + _pevent_unref(ev); \ + } while (0) + ++#define PEVENT_SET_OCCURRED(ctx, ev) \ ++ do { \ ++ (ev)->flags |= PEVENT_OCCURRED; \ ++ if ((ev) != TAILQ_FIRST(&ctx->events)) { \ ++ TAILQ_REMOVE(&(ctx)->events, (ev), next); \ ++ TAILQ_INSERT_HEAD(&(ctx)->events, (ev), next); \ ++ } \ ++ } while (0) ++ + /* Internal functions */ + static void pevent_ctx_service(struct pevent *ev); + static void *pevent_ctx_main(void *arg); +@@ -436,7 +445,7 @@ + goto done; + + /* Mark event as having occurred */ +- ev->flags |= PEVENT_OCCURRED; ++ PEVENT_SET_OCCURRED(ctx, ev); + + /* Wake up thread if event is still in the queue */ + if ((ev->flags & PEVENT_ENQUEUED) != 0) +@@ -490,6 +499,7 @@ + struct timeval now; + struct pollfd *fd; + struct pevent *ev; ++ struct pevent *next_ev; + int poll_idx; + int timeout; + int r; +@@ -529,6 +539,13 @@ + } + } + ++ /* If we were intentionally woken up, read the wakeup byte */ ++ if (ctx->notified) { ++ DBG(PEVENT, "ctx %p thread was notified", ctx); ++ (void)read(ctx->pipe[0], &pevent_byte, 1); ++ ctx->notified = 0; ++ } ++ + /* Add event for the notify pipe */ + poll_idx = 0; + if (ctx->fds_alloc > 0) { +@@ -587,7 +604,7 @@ + switch (ev->type) { + case PEVENT_MESG_PORT: + if (mesg_port_qlen(ev->u.port) > 0) +- ev->flags |= PEVENT_OCCURRED; ++ PEVENT_SET_OCCURRED(ctx, ev); + break; + default: + break; +@@ -621,7 +638,8 @@ + gettimeofday(&now, NULL); + + /* Mark poll() events that have occurred */ +- TAILQ_FOREACH(ev, &ctx->events, next) { ++ for (ev = TAILQ_FIRST((&ctx->events)); ev != NULL; ev = next_ev) { ++ next_ev = TAILQ_NEXT(ev, next); + assert(ev->magic == PEVENT_MAGIC); + switch (ev->type) { + case PEVENT_READ: +@@ -631,33 +649,23 @@ + fd = &ctx->fds[ev->poll_idx]; + if ((fd->revents & ((ev->type == PEVENT_READ) ? + READABLE_EVENTS : WRITABLE_EVENTS)) != 0) +- ev->flags |= PEVENT_OCCURRED; ++ PEVENT_SET_OCCURRED(ctx, ev); + break; + case PEVENT_TIME: + if (timercmp(&ev->when, &now, <=)) +- ev->flags |= PEVENT_OCCURRED; ++ PEVENT_SET_OCCURRED(ctx, ev); + break; + default: + break; + } + } + +- /* If we were intentionally woken up, read the wakeup byte */ +- if (ctx->notified) { +- DBG(PEVENT, "ctx %p thread was notified", ctx); +- (void)read(ctx->pipe[0], &pevent_byte, 1); +- ctx->notified = 0; +- } +- + /* Service all events that are marked as having occurred */ + while (1) { + +- /* Find next event that needs service XXX this is O(n^2) XXX */ +- TAILQ_FOREACH(ev, &ctx->events, next) { +- if ((ev->flags & PEVENT_OCCURRED) != 0) +- break; +- } +- if (ev == NULL) ++ /* Find next event that needs service */ ++ ev = TAILQ_FIRST(&ctx->events); ++ if (ev == NULL || (ev->flags & PEVENT_OCCURRED) == 0) + break; + DBG(PEVENT, "ctx %p thread servicing ev %p", ctx, ev); + |