summaryrefslogtreecommitdiffstats
path: root/runtime/wtp.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-04-02 14:49:04 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-04-02 14:49:04 +0200
commitc250c50633d615ad261d8b3ff0e491f1032de5f6 (patch)
treee684746f76c4ba8086a2b7efee81c18c9e1dad16 /runtime/wtp.c
parentae7a01e137f14055f9472408d0cf3ebf9893afba (diff)
parent01adeab0cba21ad6193addf1a4e90689b507d092 (diff)
downloadrsyslog-c250c50633d615ad261d8b3ff0e491f1032de5f6.tar.gz
rsyslog-c250c50633d615ad261d8b3ff0e491f1032de5f6.tar.xz
rsyslog-c250c50633d615ad261d8b3ff0e491f1032de5f6.zip
Merge branch 'v3-stable' into beta
Conflicts: ChangeLog configure.ac doc/manual.html
Diffstat (limited to 'runtime/wtp.c')
-rw-r--r--runtime/wtp.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/runtime/wtp.c b/runtime/wtp.c
index 734c8d57..3beae271 100644
--- a/runtime/wtp.c
+++ b/runtime/wtp.c
@@ -76,6 +76,7 @@ static rsRetVal NotImplementedDummy() { return RS_RET_OK; }
*/
BEGINobjConstruct(wtp) /* be sure to specify the object type also in END macro! */
pthread_mutex_init(&pThis->mut, NULL);
+ pthread_mutex_init(&pThis->mutThrdShutdwn, NULL);
pthread_cond_init(&pThis->condThrdTrm, NULL);
/* set all function pointers to "not implemented" dummy so that we can safely call them */
pThis->pfChkStopWrkr = NotImplementedDummy;
@@ -140,6 +141,7 @@ CODESTARTobjDestruct(wtp)
/* actual destruction */
pthread_cond_destroy(&pThis->condThrdTrm);
pthread_mutex_destroy(&pThis->mut);
+ pthread_mutex_destroy(&pThis->mutThrdShutdwn);
if(pThis->pszDbgHdr != NULL)
free(pThis->pszDbgHdr);
@@ -191,11 +193,31 @@ wtpProcessThrdChanges(wtp_t *pThis)
if(pThis->bThrdStateChanged == 0)
FINALIZE;
- /* go through all threads */
- for(i = 0 ; i < pThis->iNumWorkerThreads ; ++i) {
- wtiProcessThrdChanges(pThis->pWrkr[i], LOCK_MUTEX);
+ if(d_pthread_mutex_trylock(&(pThis->mutThrdShutdwn)) != 0) {
+ /* another thread is already in the loop */
+ FINALIZE;
}
+ /* Note: there is a left-over potential race condition below:
+ * pThis->bThrdStateChanged may be re-set by another thread while
+ * we work on it and thus the loop may terminate too early. However,
+ * there are no really bad effects from that so I perfer - for this
+ * version - to live with the problem as is. Not a good idea to
+ * introduce that large change into the stable branch without very
+ * good reason. -- rgerhards, 2009-04-02
+ */
+ do {
+ /* reset the change marker */
+ pThis->bThrdStateChanged = 0;
+ /* go through all threads */
+ for(i = 0 ; i < pThis->iNumWorkerThreads ; ++i) {
+ wtiProcessThrdChanges(pThis->pWrkr[i], LOCK_MUTEX);
+ }
+ /* restart if another change occured while we were processing the changes */
+ } while(pThis->bThrdStateChanged != 0);
+
+ d_pthread_mutex_unlock(&(pThis->mutThrdShutdwn));
+
finalize_it:
RETiRet;
}