diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2010-05-17 14:24:27 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2010-05-17 14:24:27 +0200 |
commit | af8582e50914cfc719be1a1a80eeb81030d611c5 (patch) | |
tree | 0ece18d61b635e07c4f1f6bfeefe31a96286b2ad /runtime/wti.c | |
parent | 74f8bf146546275e296a3d5af17cc4c6d0397778 (diff) | |
download | rsyslog-af8582e50914cfc719be1a1a80eeb81030d611c5.tar.gz rsyslog-af8582e50914cfc719be1a1a80eeb81030d611c5.tar.xz rsyslog-af8582e50914cfc719be1a1a80eeb81030d611c5.zip |
added new cancel-reduced action thread termination method
We now manage to cancel threads that block inside a retry loop to
terminate without the need to cancel the thread. Avoiding cancellation
helps keep the system complexity minimal and thus provides for better
stability. This also solves some issues with improper shutdown when
inside an action retry loop.
Diffstat (limited to 'runtime/wti.c')
-rw-r--r-- | runtime/wti.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/runtime/wti.c b/runtime/wti.c index 44a27b3e..2dfc2d3f 100644 --- a/runtime/wti.c +++ b/runtime/wti.c @@ -109,6 +109,29 @@ wtiSetState(wti_t *pThis, sbool bNewVal) } +/* advise all workers to start by interrupting them. That should unblock all srSleep() + * calls. + */ +rsRetVal +wtiWakeupThrd(wti_t *pThis) +{ + DEFiRet; + + ISOBJ_TYPE_assert(pThis, wti); + + + if(wtiGetState(pThis)) { + /* we first try the cooperative "cancel" interface */ + pthread_kill(pThis->thrdID, SIGTTIN); + dbgprintf("sent SIGTTIN to worker thread %u, giving it a chance to terminate\n", (unsigned) pThis->thrdID); + srSleep(0, 10000); + dbgprintf("cooperative worker termination failed, using cancellation...\n"); + } + + RETiRet; +} + + /* Cancel the thread. If the thread is not running. But it is save and legal to * call wtiCancelThrd() in such situations. This function only returns when the * thread has terminated. Else we may get race conditions all over the code... @@ -125,7 +148,16 @@ wtiCancelThrd(wti_t *pThis) ISOBJ_TYPE_assert(pThis, wti); + if(wtiGetState(pThis)) { + /* we first try the cooperative "cancel" interface */ +#if 0 + pthread_kill(pThis->thrdID, SIGTTIN); + dbgprintf("sent SIGTTIN to worker thread %u, giving it a chance to terminate\n", (unsigned) pThis->thrdID); + srSleep(0, 10000); + dbgprintf("cooperative worker termination failed, using cancellation...\n"); +#endif + dbgoprint((obj_t*) pThis, "canceling worker thread\n"); pthread_cancel(pThis->thrdID); /* now wait until the thread terminates... */ |