aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/job_queue.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2005-11-04 13:20:11 +0000
committerMartin Willi <martin@strongswan.org>2005-11-04 13:20:11 +0000
commitdb5dc986036b6e369925c7958ebee509714cbd9f (patch)
treeb74324dc536ae301459b34e5ab88ac9af1dec0c5 /Source/charon/job_queue.c
parentbfdc5c7c93b0d5a7ed61892d686447ec94fb6405 (diff)
downloadstrongswan-db5dc986036b6e369925c7958ebee509714cbd9f.tar.bz2
strongswan-db5dc986036b6e369925c7958ebee509714cbd9f.tar.xz
- cancellation disabled by default
Diffstat (limited to 'Source/charon/job_queue.c')
-rw-r--r--Source/charon/job_queue.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/Source/charon/job_queue.c b/Source/charon/job_queue.c
index e4ab78c2f..14f0a4ed9 100644
--- a/Source/charon/job_queue.c
+++ b/Source/charon/job_queue.c
@@ -96,19 +96,22 @@ status_t get_count(private_job_queue_t *this, int *count)
status_t get(private_job_queue_t *this, job_t **job)
{
int count;
+ int oldstate;
pthread_mutex_lock(&(this->mutex));
- // add mutex unlock handler for cancellation
- pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
- // go to wait while no jobs available
+ /* go to wait while no jobs available */
this->list->get_count(this->list,&count);
while(count == 0)
{
+ /* add mutex unlock handler for cancellation, enable cancellation */
+ pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
pthread_cond_wait( &(this->condvar), &(this->mutex));
+
+ /* reset cancellation, remove mutex-unlock handler (without executing) */
+ pthread_setcancelstate(oldstate, NULL);
+ pthread_cleanup_pop(0);
this->list->get_count(this->list,&count);
}
- // remove mutex-unlock handler (without executing)
- pthread_cleanup_pop(0);
-
this->list->remove_first(this->list,(void **) job);
pthread_mutex_unlock(&(this->mutex));
return SUCCESS;