summaryrefslogtreecommitdiffstats
path: root/runtime/queue.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-09-18 12:19:33 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2008-09-18 12:19:33 +0200
commit4c96ebdcfe075e80810b01257cf21ea1c9b3ec0e (patch)
treeb6768398d8d55c04e045b5213e11b952484025e8 /runtime/queue.c
parent988989e49ef8639123c83383ba256c4e67679c8d (diff)
downloadrsyslog-4c96ebdcfe075e80810b01257cf21ea1c9b3ec0e.tar.gz
rsyslog-4c96ebdcfe075e80810b01257cf21ea1c9b3ec0e.tar.xz
rsyslog-4c96ebdcfe075e80810b01257cf21ea1c9b3ec0e.zip
bugfix: potential race condition when adding messages to queue
There was a wrong order of mutex lock operations. It is hard to believe that really caused problems, but in theory it could and with threading we often see that theory becomes practice if something is only used long enough on a fast enough machine with enough CPUs ;)
Diffstat (limited to 'runtime/queue.c')
-rw-r--r--runtime/queue.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/runtime/queue.c b/runtime/queue.c
index 7e7d4152..c0a37019 100644
--- a/runtime/queue.c
+++ b/runtime/queue.c
@@ -2171,17 +2171,17 @@ queueEnqObj(queue_t *pThis, flowControl_t flowCtlType, void *pUsr)
finalize_it:
if(pThis->qType != QUEUETYPE_DIRECT) {
- d_pthread_mutex_unlock(pThis->mut);
+ /* make sure at least one worker is running. */
+ if(pThis->qType != QUEUETYPE_DIRECT) {
+ queueAdviseMaxWorkers(pThis);
+ }
+ /* and release the mutex */
i = pthread_cond_signal(&pThis->notEmpty);
+ d_pthread_mutex_unlock(pThis->mut);
dbgoprint((obj_t*) pThis, "EnqueueMsg signaled condition (%d)\n", i);
pthread_setcancelstate(iCancelStateSave, NULL);
}
- /* make sure at least one worker is running. */
- if(pThis->qType != QUEUETYPE_DIRECT) {
- queueAdviseMaxWorkers(pThis);
- }
-
RETiRet;
}