summaryrefslogtreecommitdiffstats
path: root/runtime/wti.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-07-20 11:52:05 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-07-20 11:52:05 +0200
commit4ec7b9d9ec12d91dde3d030bdaf87cfdd6b5d81d (patch)
treea08d9a3b839f40bb5d26d06f5b2b54787277faf9 /runtime/wti.c
parentef70e6174d4b373a601b73757ca19bb0f7dd6502 (diff)
downloadrsyslog-4ec7b9d9ec12d91dde3d030bdaf87cfdd6b5d81d.tar.gz
rsyslog-4ec7b9d9ec12d91dde3d030bdaf87cfdd6b5d81d.tar.xz
rsyslog-4ec7b9d9ec12d91dde3d030bdaf87cfdd6b5d81d.zip
enhanced worker thread pool by atomic ops
... greater performance and was able to remove a potential troublespot in a cancel cleanup handler.
Diffstat (limited to 'runtime/wti.c')
-rw-r--r--runtime/wti.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/runtime/wti.c b/runtime/wti.c
index 1d8f075f..91c63ffe 100644
--- a/runtime/wti.c
+++ b/runtime/wti.c
@@ -82,7 +82,7 @@ wtiGetDbgHdr(wti_t *pThis)
bool
wtiGetState(wti_t *pThis)
{
- return pThis->bIsRunning;
+ return ATOMIC_FETCH_32BIT(pThis->bIsRunning);
}
@@ -105,14 +105,16 @@ rsRetVal
wtiSetState(wti_t *pThis, bool bNewVal)
{
ISOBJ_TYPE_assert(pThis, wti);
- pThis->bIsRunning = bNewVal;
+ if(bNewVal)
+ ATOMIC_STORE_1_TO_INT(pThis->bIsRunning);
+ else
+ ATOMIC_STORE_0_TO_INT(pThis->bIsRunning);
return RS_RET_OK;
}
/* Cancel the thread. If the thread is not running. But it is save and legal to
* call wtiCancelThrd() in such situations.
- * IMPORTANT: WTP mutex must be locked while this function is called!
* rgerhards, 2008-02-26
*/
rsRetVal
@@ -122,7 +124,7 @@ wtiCancelThrd(wti_t *pThis)
ISOBJ_TYPE_assert(pThis, wti);
- if(pThis->bIsRunning) {
+ if(wtiGetState(pThis)) {
dbgoprint((obj_t*) pThis, "canceling worker thread\n");
pthread_cancel(pThis->thrdID);
}
@@ -159,7 +161,7 @@ wtiConstructFinalize(wti_t *pThis)
dbgprintf("%s: finalizing construction of worker instance data\n", wtiGetDbgHdr(pThis));
- /* initialize our thread instance descriptor */
+ /* initialize our thread instance descriptor (no concurrency here) */
pThis->bIsRunning = FALSE;
/* we now alloc the array for user pointers. We obtain the max from the queue itself. */