select loop changes for persistent threads

This commit is contained in:
Jong Hyuk Choi 2003-05-20 23:52:11 +00:00
parent 2b62559aa5
commit 4192c4aaaa
3 changed files with 46 additions and 4 deletions

View file

@ -61,4 +61,9 @@ ldap_pvt_runqueue_resched(
struct re_s* entry
);
LDAP_F( int )
ldap_pvt_runqueue_persistent_backload(
struct runqueue_s* rq
);
#endif

View file

@ -69,6 +69,9 @@ ldap_pvt_runqueue_next_sched(
if ( entry == NULL ) {
*next_run = NULL;
return NULL;
} else if ( entry->next_sched.tv_sec == 0 ) {
*next_run = NULL;
return NULL;
} else {
*next_run = &entry->next_sched;
return entry;
@ -127,22 +130,54 @@ ldap_pvt_runqueue_resched(
LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
if ( entry->interval.tv_sec ) {
entry->next_sched.tv_sec = time( NULL ) + entry->interval.tv_sec;
} else {
entry->next_sched.tv_sec = 0;
}
if ( LDAP_STAILQ_EMPTY( &rq->task_list )) {
LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
} else if ( entry->next_sched.tv_sec == 0 ) {
LDAP_STAILQ_INSERT_TAIL( &rq->task_list, entry, tnext );
} else {
prev = NULL;
LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
if ( e->next_sched.tv_sec > entry->next_sched.tv_sec ) {
if ( e->next_sched.tv_sec == 0 ) {
if ( prev == NULL ) {
LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
} else {
LDAP_STAILQ_INSERT_AFTER( &rq->task_list, prev, entry, tnext );
}
break;
} else if ( e->next_sched.tv_sec > entry->next_sched.tv_sec ) {
if ( prev == NULL ) {
LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
} else {
LDAP_STAILQ_INSERT_AFTER( &rq->task_list, prev, entry, tnext );
}
break;
}
prev = e;
}
}
}
int
ldap_pvt_runqueue_persistent_backload(
struct runqueue_s* rq
)
{
struct re_s* e;
int count = 0;
if ( !LDAP_STAILQ_EMPTY( &rq->task_list )) {
LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
if ( e->next_sched.tv_sec == 0 )
count++;
}
}
return count;
}
#endif

View file

@ -1329,8 +1329,10 @@ slapd_daemon_task(
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
if ( !at )
at = ldap_pvt_thread_pool_backload(&connection_pool);
if ( !at ) {
at = ldap_pvt_thread_pool_backload(&connection_pool) -
ldap_pvt_runqueue_persistent_backload( &syncrepl_rq );
}
tvp = at ? &tv : NULL;