diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2009-03-25 17:21:56 +0100 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2009-03-25 17:21:56 +0100 |
commit | 611b3364491cf30dc866932a053ae925e1f182ac (patch) | |
tree | 1318d02e01c72ce8e3e869e6b8977f45477ae100 /runtime/wtp.c | |
parent | 7269efe60a2071e17f68f96b6416acaefeb7068d (diff) | |
parent | 6ffb9010811ee9bc0c3703716443c4dd00922f6f (diff) | |
download | rsyslog-611b3364491cf30dc866932a053ae925e1f182ac.tar.gz rsyslog-611b3364491cf30dc866932a053ae925e1f182ac.tar.xz rsyslog-611b3364491cf30dc866932a053ae925e1f182ac.zip |
Merge branch 'dapatch'
Diffstat (limited to 'runtime/wtp.c')
-rw-r--r-- | runtime/wtp.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/runtime/wtp.c b/runtime/wtp.c index 41903576..9f54a9ab 100644 --- a/runtime/wtp.c +++ b/runtime/wtp.c @@ -84,6 +84,7 @@ static rsRetVal NotImplementedDummy() { return RS_RET_OK; } BEGINobjConstruct(wtp) /* be sure to specify the object type also in END macro! */ pThis->bOptimizeUniProc = glbl.GetOptimizeUniProc(); 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; @@ -148,6 +149,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); @@ -199,11 +201,23 @@ 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; } + 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; } |