13 #include "ldap_pvt_thread.h"
14 #include "ldap_queue.h"
20 ldap_pvt_runqueue_insert(
21 struct runqueue_s* rq,
28 entry = (struct re_s *) ch_calloc( 1, sizeof( struct re_s ));
29 entry->interval.tv_sec = interval;
30 entry->interval.tv_usec = 0;
31 entry->next_sched.tv_sec = time( NULL );
32 entry->next_sched.tv_usec = 0;
33 entry->private = private;
34 LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
38 ldap_pvt_runqueue_remove(
39 struct runqueue_s* rq,
45 LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
50 assert ( e == entry );
52 LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
59 ldap_pvt_runqueue_next_sched(
60 struct runqueue_s* rq,
61 struct timeval** next_run
66 entry = LDAP_STAILQ_FIRST( &rq->task_list );
67 if ( entry == NULL ) {
71 *next_run = &entry->next_sched;
77 ldap_pvt_runqueue_runtask(
78 struct runqueue_s* rq,
82 LDAP_STAILQ_INSERT_HEAD( &rq->run_list, entry, rnext );
86 ldap_pvt_runqueue_stoptask(
87 struct runqueue_s* rq,
91 LDAP_STAILQ_REMOVE( &rq->run_list, entry, re_s, rnext );
95 ldap_pvt_runqueue_isrunning(
96 struct runqueue_s* rq,
102 LDAP_STAILQ_FOREACH( e, &rq->run_list, rnext ) {
111 ldap_pvt_runqueue_resched(
112 struct runqueue_s* rq,
119 LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
124 assert ( e == entry );
126 LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
128 entry->next_sched.tv_sec = time( NULL ) + entry->interval.tv_sec;
129 if ( LDAP_STAILQ_EMPTY( &rq->task_list )) {
130 LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
133 LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
134 if ( e->next_sched.tv_sec > entry->next_sched.tv_sec ) {
135 if ( prev == NULL ) {
136 LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
138 LDAP_STAILQ_INSERT_AFTER( &rq->task_list, prev, entry, tnext );