X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap_r%2Frq.c;h=a1b432051e48deaa9fba6109b55dabb9e3f1e081;hb=8452b4ccde09a41c7e21cff66ec4f566b1a34e28;hp=194d16db8eda17e77969da03b883bbc064771bde;hpb=763f8c76ee0d8afbb86b7a1ca727f32b010dd7c4;p=openldap diff --git a/libraries/libldap_r/rq.c b/libraries/libldap_r/rq.c index 194d16db8e..a1b432051e 100644 --- a/libraries/libldap_r/rq.c +++ b/libraries/libldap_r/rq.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2003-2004 The OpenLDAP Foundation. + * Copyright 2003-2012 The OpenLDAP Foundation. * Portions Copyright 2003 IBM Corporation. * All rights reserved. * @@ -33,24 +33,47 @@ #include "ldap_queue.h" #include "ldap_rq.h" -void +struct re_s * ldap_pvt_runqueue_insert( struct runqueue_s* rq, time_t interval, ldap_pvt_thread_start_t *routine, - void *arg + void *arg, + char *tname, + char *tspec ) { struct re_s* entry; entry = (struct re_s *) LDAP_CALLOC( 1, sizeof( struct re_s )); - entry->interval.tv_sec = interval; - entry->interval.tv_usec = 0; - entry->next_sched.tv_sec = time( NULL ); - entry->next_sched.tv_usec = 0; - entry->routine = routine; - entry->arg = arg; - LDAP_STAILQ_INSERT_TAIL( &rq->task_list, entry, tnext ); + if ( entry ) { + entry->interval.tv_sec = interval; + entry->interval.tv_usec = 0; + entry->next_sched.tv_sec = time( NULL ); + entry->next_sched.tv_usec = 0; + entry->routine = routine; + entry->arg = arg; + entry->tname = tname; + entry->tspec = tspec; + LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext ); + } + return entry; +} + +struct re_s * +ldap_pvt_runqueue_find( + struct runqueue_s *rq, + ldap_pvt_thread_start_t *routine, + void *arg +) +{ + struct re_s* e; + + LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) { + if ( e->routine == routine && e->arg == arg ) + return e; + } + return NULL; } void @@ -66,9 +89,9 @@ ldap_pvt_runqueue_remove( break; } - if ( e == entry ) { - LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext ); - } + assert( e == entry ); + + LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext ); LDAP_FREE( entry ); } @@ -76,20 +99,16 @@ ldap_pvt_runqueue_remove( struct re_s* ldap_pvt_runqueue_next_sched( struct runqueue_s* rq, - struct timeval** next_run + struct timeval* next_run ) { struct re_s* entry; entry = LDAP_STAILQ_FIRST( &rq->task_list ); - if ( entry == NULL ) { - *next_run = NULL; - return NULL; - } else if ( entry->next_sched.tv_sec == 0 ) { - *next_run = NULL; + if ( entry == NULL || entry->next_sched.tv_sec == 0 ) { return NULL; } else { - *next_run = &entry->next_sched; + *next_run = entry->next_sched; return entry; } }