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 ) {
72 } else if ( entry->next_sched.tv_sec == 0 ) {
76 *next_run = &entry->next_sched;
82 ldap_pvt_runqueue_runtask(
83 struct runqueue_s* rq,
87 LDAP_STAILQ_INSERT_HEAD( &rq->run_list, entry, rnext );
91 ldap_pvt_runqueue_stoptask(
92 struct runqueue_s* rq,
96 LDAP_STAILQ_REMOVE( &rq->run_list, entry, re_s, rnext );
100 ldap_pvt_runqueue_isrunning(
101 struct runqueue_s* rq,
107 LDAP_STAILQ_FOREACH( e, &rq->run_list, rnext ) {
116 ldap_pvt_runqueue_resched(
117 struct runqueue_s* rq,
124 LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
129 assert ( e == entry );
131 LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
133 if ( entry->interval.tv_sec ) {
134 entry->next_sched.tv_sec = time( NULL ) + entry->interval.tv_sec;
136 entry->next_sched.tv_sec = 0;
139 if ( LDAP_STAILQ_EMPTY( &rq->task_list )) {
140 LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
141 } else if ( entry->next_sched.tv_sec == 0 ) {
142 LDAP_STAILQ_INSERT_TAIL( &rq->task_list, entry, tnext );
145 LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
146 if ( e->next_sched.tv_sec == 0 ) {
147 if ( prev == NULL ) {
148 LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
150 LDAP_STAILQ_INSERT_AFTER( &rq->task_list, prev, entry, tnext );
153 } else if ( e->next_sched.tv_sec > entry->next_sched.tv_sec ) {
154 if ( prev == NULL ) {
155 LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
157 LDAP_STAILQ_INSERT_AFTER( &rq->task_list, prev, entry, tnext );
167 ldap_pvt_runqueue_persistent_backload(
168 struct runqueue_s* rq
174 if ( !LDAP_STAILQ_EMPTY( &rq->task_list )) {
175 LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
176 if ( e->next_sched.tv_sec == 0 )