X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap_r%2Frq.c;h=a1b432051e48deaa9fba6109b55dabb9e3f1e081;hb=8452b4ccde09a41c7e21cff66ec4f566b1a34e28;hp=eed92e72e9fa328bfdd717689afe31ce94e998d5;hpb=0a7a97d294863dc68dc94f1bfb35e429b627e6f1;p=openldap
diff --git a/libraries/libldap_r/rq.c b/libraries/libldap_r/rq.c
index eed92e72e9..a1b432051e 100644
--- a/libraries/libldap_r/rq.c
+++ b/libraries/libldap_r/rq.c
@@ -1,24 +1,20 @@
/* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
- */
-/* Copyright (c) 2003 by International Business Machines, Inc.
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 2003-2012 The OpenLDAP Foundation.
+ * Portions Copyright 2003 IBM Corporation.
+ * All rights reserved.
*
- * International Business Machines, Inc. (hereinafter called IBM) grants
- * permission under its copyrights to use, copy, modify, and distribute this
- * Software with or without fee, provided that the above copyright notice and
- * all paragraphs of this notice appear in all copies, and that the name of IBM
- * not be used in connection with the marketing of any product incorporating
- * the Software or modifications thereof, without specific, written prior
- * permission.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
*
- * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
- * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
- * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ * A copy of this license is available in file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * .
+ */
+/* This work was initially developed by Jong Hyuk Choi for inclusion
+ * in OpenLDAP Software.
*/
#include "portable.h"
@@ -37,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_HEAD( &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
@@ -70,31 +89,26 @@ ldap_pvt_runqueue_remove(
break;
}
- assert ( e == entry );
+ assert( e == entry );
LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
LDAP_FREE( entry );
-
}
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;
}
}
@@ -105,7 +119,7 @@ ldap_pvt_runqueue_runtask(
struct re_s* entry
)
{
- LDAP_STAILQ_INSERT_HEAD( &rq->run_list, entry, rnext );
+ LDAP_STAILQ_INSERT_TAIL( &rq->run_list, entry, rnext );
}
void
@@ -152,7 +166,7 @@ ldap_pvt_runqueue_resched(
LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
- if ( entry->interval.tv_sec && !defer ) {
+ if ( !defer ) {
entry->next_sched.tv_sec = time( NULL ) + entry->interval.tv_sec;
} else {
entry->next_sched.tv_sec = 0;
@@ -171,17 +185,18 @@ ldap_pvt_runqueue_resched(
} else {
LDAP_STAILQ_INSERT_AFTER( &rq->task_list, prev, entry, tnext );
}
- break;
+ return;
} else 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 );
}
- break;
+ return;
}
prev = e;
}
+ LDAP_STAILQ_INSERT_TAIL( &rq->task_list, entry, tnext );
}
}