13 #include "ldap_pvt_thread.h"
14 #include "ldap_queue.h"
18 ldap_pvt_runqueue_insert(
19 struct runqueue_s* rq,
25 entry = (struct re_s *) ch_calloc( 1, sizeof( struct re_s ));
26 entry->interval.tv_sec = interval;
27 entry->interval.tv_usec = 0;
28 entry->next_sched.tv_sec = time( NULL );
29 entry->next_sched.tv_usec = 0;
30 entry->private = private;
31 LDAP_STAILQ_INSERT_HEAD( &rq->run_list, entry, next );
35 ldap_pvt_runqueue_next_sched(
36 struct runqueue_s* rq,
37 struct timeval** next_run,
42 entry = LDAP_STAILQ_FIRST( &rq->run_list );
43 if ( entry == NULL ) {
47 *next_run = &entry->next_sched;
48 *private = entry->private;
53 ldap_pvt_runqueue_resched(
61 entry = LDAP_STAILQ_FIRST( &rq->run_list );
62 if ( entry == NULL ) {
65 entry->next_sched.tv_sec = time( NULL ) + entry->interval.tv_sec;
66 LDAP_STAILQ_REMOVE_HEAD( &rq->run_list, next );
67 if ( LDAP_STAILQ_EMPTY( &rq->run_list )) {
68 LDAP_STAILQ_INSERT_HEAD( &rq->run_list, entry, next );
71 LDAP_STAILQ_FOREACH( e, &rq->run_list, next ) {
72 if ( e->next_sched.tv_sec > entry->next_sched.tv_sec ) {
73 if ( prev == entry ) {
74 LDAP_STAILQ_INSERT_HEAD( &rq->run_list, entry, next );
76 LDAP_STAILQ_INSERT_AFTER( &rq->run_list, prev, entry, next );