ITS#9878 Treat tasks with interval == 0 as one-shot

Some tasks need to be run once at a given time or the earliest
opportunity, also currently, using interval == 0 on a task triggers
a busy loop inside the scheduling task, halting progress for other
tasks and any other work usually serviced by that thread.

This change deals with both issues at the same time.
This commit is contained in:
Ondřej Kuzník 2022-09-07 09:53:57 +01:00
parent 294a16c10c
commit 29c3a443d8

View file

@ -2788,11 +2788,13 @@ loop:
ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
rtask = ldap_pvt_runqueue_next_sched( &slapd_rq, &cat );
while ( rtask && cat.tv_sec && cat.tv_sec <= now ) {
/* ITS#9878 If interval == 0, this task was meant to be one-shot */
int defer = !rtask->interval.tv_sec;
if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) {
ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
ldap_pvt_runqueue_resched( &slapd_rq, rtask, defer );
} else {
ldap_pvt_runqueue_runtask( &slapd_rq, rtask );
ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
ldap_pvt_runqueue_resched( &slapd_rq, rtask, defer );
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
ldap_pvt_thread_pool_submit2( &connection_pool,
slapd_rtask_trampoline, (void *) rtask, &rtask->pool_cookie );