Do not execute the callback job if it has been cancelled since registration

This commit is contained in:
Martin Willi
2009-12-03 08:00:43 +01:00
parent c636bc7e17
commit cd51437e43
+8 -2
View File
@@ -126,6 +126,8 @@ static void cancel(private_callback_job_t *this)
pthread_cancel(thread); pthread_cancel(thread);
pthread_join(thread, NULL); pthread_join(thread, NULL);
} }
/* avoid later execution of a cancelled job */
this->callback = NULL;
} }
/** /**
@@ -142,13 +144,17 @@ static void execute(private_callback_job_t *this)
pthread_cleanup_push((void*)destroy, this); pthread_cleanup_push((void*)destroy, this);
while (TRUE) while (TRUE)
{ {
if (this->callback == NULL)
{
cleanup = TRUE;
break;
}
switch (this->callback(this->data)) switch (this->callback(this->data))
{ {
case JOB_REQUEUE_DIRECT: case JOB_REQUEUE_DIRECT:
continue; continue;
case JOB_REQUEUE_FAIR: case JOB_REQUEUE_FAIR:
{ {
this->thread = 0;
charon->processor->queue_job(charon->processor, charon->processor->queue_job(charon->processor,
&this->public.job_interface); &this->public.job_interface);
break; break;
@@ -156,13 +162,13 @@ static void execute(private_callback_job_t *this)
case JOB_REQUEUE_NONE: case JOB_REQUEUE_NONE:
default: default:
{ {
this->thread = 0;
cleanup = TRUE; cleanup = TRUE;
break; break;
} }
} }
break; break;
} }
this->thread = 0;
unregister(this); unregister(this);
pthread_cleanup_pop(cleanup); pthread_cleanup_pop(cleanup);
} }