summaryrefslogtreecommitdiffstats
path: root/runtime/wtp.c
diff options
context:
space:
mode:
authorPavel Levshin <pavel@levshin.spb.ru>2013-11-06 18:37:47 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2013-11-06 18:37:47 +0100
commit772cba6f2e34660fa74a7e2f5ec2823a2cdb6b04 (patch)
treedd485659f80ef4cc00b28b1194a73fef0f35f5d6 /runtime/wtp.c
parent6b0e236cdf3d55299de70cf41dafdefec286f103 (diff)
downloadrsyslog-772cba6f2e34660fa74a7e2f5ec2823a2cdb6b04.tar.gz
rsyslog-772cba6f2e34660fa74a7e2f5ec2823a2cdb6b04.tar.bz2
rsyslog-772cba6f2e34660fa74a7e2f5ec2823a2cdb6b04.zip
improve worker thread pool handling
among others, make possible that workers really timeout and the pool thus shrinks
Diffstat (limited to 'runtime/wtp.c')
-rw-r--r--runtime/wtp.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/runtime/wtp.c b/runtime/wtp.c
index 19151e7c..0326d5dc 100644
--- a/runtime/wtp.c
+++ b/runtime/wtp.c
@@ -233,9 +233,9 @@ wtpShutdownAll(wtp_t *pThis, wtpState_t tShutdownCmd, struct timespec *ptTimeout
/* lock mutex to prevent races (may otherwise happen during idle processing and such...) */
d_pthread_mutex_lock(pThis->pmutUsr);
wtpSetState(pThis, tShutdownCmd);
- pthread_cond_broadcast(pThis->pcondBusy); /* wake up all workers */
/* awake workers in retry loop */
for(i = 0 ; i < pThis->iNumWorkerThreads ; ++i) {
+ pthread_cond_signal(&pThis->pWrkr[i]->pcondBusy);
wtiWakeupThrd(pThis->pWrkr[i]);
}
d_pthread_mutex_unlock(pThis->pmutUsr);
@@ -455,7 +455,7 @@ wtpAdviseMaxWorkers(wtp_t *pThis, int nMaxWrkr)
{
DEFiRet;
int nMissing; /* number workers missing to run */
- int i;
+ int i, nRunning;
ISOBJ_TYPE_assert(pThis, wtp);
@@ -475,7 +475,13 @@ wtpAdviseMaxWorkers(wtp_t *pThis, int nMaxWrkr)
CHKiRet(wtpStartWrkr(pThis));
}
} else {
- pthread_cond_signal(pThis->pcondBusy);
+ /* we have needed number of workers, but they may be sleeping */
+ for(i = 0, nRunning = 0; i < pThis->iNumWorkerThreads && nRunning < nMaxWrkr; ++i) {
+ if (wtiGetState(pThis->pWrkr[i]) != WRKTHRD_STOPPED) {
+ pthread_cond_signal(&pThis->pWrkr[i]->pcondBusy);
+ nRunning++;
+ }
+ }
}