diff options
author | sem <sem@FreeBSD.org> | 2007-02-07 00:25:27 +0800 |
---|---|---|
committer | sem <sem@FreeBSD.org> | 2007-02-07 00:25:27 +0800 |
commit | 2f392da7f05e2caf5d3055f47e45beb3d25e3625 (patch) | |
tree | a32737503eef1b571e4cd4ada67d50b14c4fed56 /devel | |
parent | df802c0fbd0584d497e6c11e9afa7ca7b05debff (diff) | |
download | freebsd-ports-gnome-2f392da7f05e2caf5d3055f47e45beb3d25e3625.tar.gz freebsd-ports-gnome-2f392da7f05e2caf5d3055f47e45beb3d25e3625.tar.zst freebsd-ports-gnome-2f392da7f05e2caf5d3055f47e45beb3d25e3625.zip |
- Add two patches.
1) Fix a race condition. It prevents UDP sockets/descriptors leak when
active RADIUS authorization used.
2) FSM events processing optimization. System calls nubers reduced
almost twice. (It makes mpd4 faster)
Submitted by: Alexander Motin <mav_at_alkar.net>
Approved by: software developers
Diffstat (limited to 'devel')
-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); + |