2003-05-07 10:06:01 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdarg.h>
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
#include <ac/errno.h>
|
|
|
|
|
|
|
|
#include "ldap-int.h"
|
|
|
|
#include "ldap_pvt_thread.h"
|
|
|
|
#include "ldap_queue.h"
|
|
|
|
#include "ldap_rq.h"
|
|
|
|
|
2003-05-08 06:29:26 +08:00
|
|
|
#ifdef LDAP_SYNCREPL
|
|
|
|
|
2003-05-07 10:06:01 +08:00
|
|
|
void
|
|
|
|
ldap_pvt_runqueue_insert(
|
|
|
|
struct runqueue_s* rq,
|
|
|
|
time_t interval,
|
|
|
|
void *private
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct re_s* entry;
|
2003-05-08 06:29:26 +08:00
|
|
|
|
2003-05-07 10:06:01 +08:00
|
|
|
entry = (struct re_s *) ch_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->private = private;
|
2003-05-08 06:29:26 +08:00
|
|
|
LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
|
2003-05-07 10:06:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-05-08 06:29:26 +08:00
|
|
|
ldap_pvt_runqueue_remove(
|
|
|
|
struct runqueue_s* rq,
|
|
|
|
struct re_s* entry
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct re_s* e;
|
|
|
|
|
|
|
|
LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
|
|
|
|
if ( e == entry)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert ( e == entry );
|
|
|
|
|
|
|
|
LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
|
|
|
|
|
|
|
|
ch_free( entry );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct re_s*
|
2003-05-07 10:06:01 +08:00
|
|
|
ldap_pvt_runqueue_next_sched(
|
|
|
|
struct runqueue_s* rq,
|
2003-05-08 06:29:26 +08:00
|
|
|
struct timeval** next_run
|
2003-05-07 10:06:01 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
struct re_s* entry;
|
2003-05-08 06:29:26 +08:00
|
|
|
|
|
|
|
entry = LDAP_STAILQ_FIRST( &rq->task_list );
|
2003-05-07 10:06:01 +08:00
|
|
|
if ( entry == NULL ) {
|
|
|
|
*next_run = NULL;
|
2003-05-08 06:29:26 +08:00
|
|
|
return NULL;
|
2003-05-07 10:06:01 +08:00
|
|
|
} else {
|
|
|
|
*next_run = &entry->next_sched;
|
2003-05-08 06:29:26 +08:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldap_pvt_runqueue_runtask(
|
|
|
|
struct runqueue_s* rq,
|
|
|
|
struct re_s* entry
|
|
|
|
)
|
|
|
|
{
|
|
|
|
LDAP_STAILQ_INSERT_HEAD( &rq->run_list, entry, rnext );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldap_pvt_runqueue_stoptask(
|
|
|
|
struct runqueue_s* rq,
|
|
|
|
struct re_s* entry
|
|
|
|
)
|
|
|
|
{
|
|
|
|
LDAP_STAILQ_REMOVE( &rq->run_list, entry, re_s, rnext );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldap_pvt_runqueue_isrunning(
|
|
|
|
struct runqueue_s* rq,
|
|
|
|
struct re_s* entry
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct re_s* e;
|
|
|
|
|
|
|
|
LDAP_STAILQ_FOREACH( e, &rq->run_list, rnext ) {
|
|
|
|
if ( e == entry ) {
|
|
|
|
return 1;
|
|
|
|
}
|
2003-05-07 10:06:01 +08:00
|
|
|
}
|
2003-05-08 06:29:26 +08:00
|
|
|
return 0;
|
2003-05-07 10:06:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldap_pvt_runqueue_resched(
|
2003-05-08 06:29:26 +08:00
|
|
|
struct runqueue_s* rq,
|
|
|
|
struct re_s* entry
|
2003-05-07 10:06:01 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
struct re_s* prev;
|
|
|
|
struct re_s* e;
|
|
|
|
|
2003-05-08 06:29:26 +08:00
|
|
|
LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
|
|
|
|
if ( e == entry )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert ( e == entry );
|
|
|
|
|
|
|
|
LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
|
|
|
|
|
|
|
|
entry->next_sched.tv_sec = time( NULL ) + entry->interval.tv_sec;
|
|
|
|
if ( LDAP_STAILQ_EMPTY( &rq->task_list )) {
|
|
|
|
LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
|
2003-05-07 10:06:01 +08:00
|
|
|
} else {
|
2003-05-08 06:29:26 +08:00
|
|
|
prev = NULL;
|
|
|
|
LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
|
|
|
|
if ( e->next_sched.tv_sec > entry->next_sched.tv_sec ) {
|
|
|
|
if ( prev == NULL ) {
|
|
|
|
LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
|
|
|
|
} else {
|
|
|
|
LDAP_STAILQ_INSERT_AFTER( &rq->task_list, prev, entry, tnext );
|
2003-05-07 10:06:01 +08:00
|
|
|
}
|
|
|
|
}
|
2003-05-08 06:29:26 +08:00
|
|
|
prev = e;
|
2003-05-07 10:06:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-05-08 06:29:26 +08:00
|
|
|
|
|
|
|
#endif
|