Make rescheduling a job more predictable

This avoids race conditions between calls to cancel() and jobs that like
to be rescheduled.  If jobs were able to reschedule themselves it would
theoretically be possible that two worker threads have the same job
assigned (the one currently executing the job and the one executing the
same but rescheduled job if it already is time to execute it), this means
that cancel() could be called twice for that job.

Creating a new job based on the current one and reschedule that is also
OK, but rescheduling itself is more efficient for jobs that need to be
executed often.
This commit is contained in:
Tobias Brunner committed 2012-06-25 17:49:12 +02:00
1 parent 26d77eb3e6
commit e0efd7c121
4 files changed
+90 -49

No files matched your search

+1 -6
View File
@@ -345,12 +345,7 @@ static job_requeue_t send_status(private_ha_segments_t *this)
message->destroy(message);
/* schedule next invocation */
lib->scheduler->schedule_job_ms(lib->scheduler, (job_t*)
callback_job_create((callback_job_cb_t)
send_status, this, NULL, NULL),
this->heartbeat_delay);
return JOB_REQUEUE_NONE;
return JOB_RESCHEDULE_MS(this->heartbeat_delay);
}
METHOD(ha_segments_t, is_active, bool,
@@ -55,7 +55,7 @@ METHOD(job_t, execute, job_requeue_t,
private_inactivity_job_t *this)
{
ike_sa_t *ike_sa;
bool rescheduled = FALSE;
u_int32_t reschedule = 0;
ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
this->reqid, TRUE);
@@ -87,9 +87,7 @@ METHOD(job_t, execute, job_requeue_t,
}
else
{
lib->scheduler->schedule_job(lib->scheduler,
&this->public.job_interface, this->timeout - diff);
rescheduled = TRUE;
reschedule = this->timeout - diff;
}
}
children++;
@@ -121,9 +119,9 @@ METHOD(job_t, execute, job_requeue_t,
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
}
if (rescheduled)
if (reschedule)
{
return JOB_REQUEUE_SCHEDULED;
return JOB_RESCHEDULE(reschedule);
}
return JOB_REQUEUE_NONE;
}