]> git.sur5r.net Git - openldap/commitdiff
runqueue restructuring
authorJong Hyuk Choi <jongchoi@openldap.org>
Wed, 7 May 2003 23:52:08 +0000 (23:52 +0000)
committerJong Hyuk Choi <jongchoi@openldap.org>
Wed, 7 May 2003 23:52:08 +0000 (23:52 +0000)
include/ldap_rq.h
libraries/libldap_r/rq.c
servers/slapd/backend.c
servers/slapd/daemon.c
servers/slapd/syncrepl.c

index 3344f902e1e9c83af972e26abda001490983098a..db83a8da1d82c61e09b6978ff5f7d11afd588a44 100644 (file)
@@ -7,7 +7,8 @@ typedef struct re_s {
        struct timeval interval;
        LDAP_STAILQ_ENTRY(re_s) tnext; /* it includes running */
        LDAP_STAILQ_ENTRY(re_s) rnext;
-       void *private;
+       ldap_pvt_thread_start_t *routine;
+       void *arg;
 } re_t;
 
 typedef struct runqueue_s {
@@ -20,7 +21,8 @@ LDAP_F( void )
 ldap_pvt_runqueue_insert(
        struct runqueue_s* rq,
        time_t interval,
-       void *private
+       ldap_pvt_thread_start_t* routine,
+       void *arg
 );
 
 LDAP_F( void )
index 4cf59c199252a20795790fa796f77d153af9bee3..f1fe099361b00c4bb822ab23bb366c2d327e136f 100644 (file)
@@ -20,7 +20,8 @@ void
 ldap_pvt_runqueue_insert(
        struct runqueue_s* rq,
        time_t interval,
-       void *private
+       ldap_pvt_thread_start_t *routine,
+       void *arg
 )
 {
        struct re_s* entry;
@@ -30,7 +31,8 @@ ldap_pvt_runqueue_insert(
        entry->interval.tv_usec = 0;
        entry->next_sched.tv_sec = time( NULL );
        entry->next_sched.tv_usec = 0;
-       entry->private = private;
+       entry->routine = routine;
+       entry->arg = arg;
        LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
 }
 
index 0075e9921c492c5fc2647c19e32133136b56925c..d2350bb44b28d73ae082373b78010e235146ff08 100644 (file)
@@ -365,7 +365,7 @@ int backend_startup(Backend *be)
                        syncinfo_t *si = ( syncinfo_t * ) backendDB[i].syncinfo;
                        ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
                        ldap_pvt_runqueue_insert( &syncrepl_rq, si->interval,
-                                                       (void *) &backendDB[i] );
+                                                       do_syncrepl, (void *) &backendDB[i] );
                        ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
                }
 #endif
index 571b8979d22dfe04109090aa28bf12894b0567da..a94349897f9829b29211bb15eec24b964dbe8a1b 100644 (file)
@@ -1297,12 +1297,25 @@ slapd_daemon_task(
                at = ldap_pvt_thread_pool_backload(&connection_pool);
 
 #ifdef LDAP_SYNCREPL
-               /* cat is of struct timeval containing the earliest schedule */
                ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
                rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat );
+               while ( cat && cat->tv_sec && cat->tv_sec <= now ) {
+                       if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) {
+                               ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
+                       } else {
+                               ldap_pvt_runqueue_runtask( &syncrepl_rq, rtask );
+                               ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
+                               ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
+                               ldap_pvt_thread_pool_submit( &connection_pool,
+                                                                                       rtask->routine, (void *) rtask );
+                       }
+                       rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat );
+               }
+               rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat );
                ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
+
                if ( cat != NULL ) {
-                       diff.tv_sec = cat->tv_sec - slap_get_time();
+                       diff.tv_sec = difftime( cat->tv_sec, now );
                        if ( diff.tv_sec == 0 )
                                diff.tv_sec = tdelta;
                }
@@ -1386,22 +1399,6 @@ slapd_daemon_task(
                            0, 0, 0 );
 #endif
 
-#ifdef LDAP_SYNCREPL
-                       ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
-                       rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat );
-                       if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) {
-                               ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
-                               ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
-                       } else if ( cat && cat->tv_sec && cat->tv_sec <= slap_get_time() ) {
-                               ldap_pvt_runqueue_runtask( &syncrepl_rq, rtask );
-                               ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
-                               ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
-                               ldap_pvt_thread_pool_submit( &connection_pool,
-                                                               do_syncrepl, (void *) rtask );
-                       } else {
-                               ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
-                       }
-#endif
                        ldap_pvt_thread_yield();
                        continue;
 
index 261287c5eb4abebc3628bbc597c4e74825f531c5..3794f00cd25adc3f6004152ac7f19a00898bc3a2 100644 (file)
@@ -119,7 +119,7 @@ do_syncrepl(
        void    *arg )
 {
        struct re_s* rtask = arg;
-       Backend *be = rtask->private;
+       Backend *be = rtask->arg;
        syncinfo_t *si = ( syncinfo_t * ) be->syncinfo;
 
        SlapReply       rs = {REP_RESULT};