13 #include "ldap_pvt_thread.h"
14 #include "ldap_queue.h"
20 ldap_pvt_runqueue_insert(
21 struct runqueue_s* rq,
23 ldap_pvt_thread_start_t *routine,
29 entry = (struct re_s *) LDAP_CALLOC( 1, sizeof( struct re_s ));
30 entry->interval.tv_sec = interval;
31 entry->interval.tv_usec = 0;
32 entry->next_sched.tv_sec = time( NULL );
33 entry->next_sched.tv_usec = 0;
34 entry->routine = routine;
36 LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
40 ldap_pvt_runqueue_remove(
41 struct runqueue_s* rq,
47 LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
52 assert ( e == entry );
54 LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
61 ldap_pvt_runqueue_next_sched(
62 struct runqueue_s* rq,
63 struct timeval** next_run
68 entry = LDAP_STAILQ_FIRST( &rq->task_list );
69 if ( entry == NULL ) {
73 *next_run = &entry->next_sched;
79 ldap_pvt_runqueue_runtask(
80 struct runqueue_s* rq,
84 LDAP_STAILQ_INSERT_HEAD( &rq->run_list, entry, rnext );
88 ldap_pvt_runqueue_stoptask(
89 struct runqueue_s* rq,
93 LDAP_STAILQ_REMOVE( &rq->run_list, entry, re_s, rnext );
97 ldap_pvt_runqueue_isrunning(
98 struct runqueue_s* rq,
104 LDAP_STAILQ_FOREACH( e, &rq->run_list, rnext ) {
113 ldap_pvt_runqueue_resched(
114 struct runqueue_s* rq,
121 LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
126 assert ( e == entry );
128 LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
130 entry->next_sched.tv_sec = time( NULL ) + entry->interval.tv_sec;
131 if ( LDAP_STAILQ_EMPTY( &rq->task_list )) {
132 LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
135 LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
136 if ( e->next_sched.tv_sec > entry->next_sched.tv_sec ) {
137 if ( prev == NULL ) {
138 LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
140 LDAP_STAILQ_INSERT_AFTER( &rq->task_list, prev, entry, tnext );