]> git.sur5r.net Git - openldap/commitdiff
select loop changes for persistent threads
authorJong Hyuk Choi <jongchoi@openldap.org>
Tue, 20 May 2003 23:52:11 +0000 (23:52 +0000)
committerJong Hyuk Choi <jongchoi@openldap.org>
Tue, 20 May 2003 23:52:11 +0000 (23:52 +0000)
include/ldap_rq.h
libraries/libldap_r/rq.c
servers/slapd/daemon.c

index db83a8da1d82c61e09b6978ff5f7d11afd588a44..0c1d1c158fd69cc7738d919a0349daf0eacb4da8 100644 (file)
@@ -61,4 +61,9 @@ ldap_pvt_runqueue_resched(
        struct re_s* entry
 );
 
+LDAP_F( int )
+ldap_pvt_runqueue_persistent_backload(
+       struct runqueue_s* rq
+);
+
 #endif
index 6977405fe4700d6155c534449fc455e2a8718206..8aa9b0b76a72c5dbb82c1609e7201d88999adbcc 100644 (file)
@@ -69,6 +69,9 @@ ldap_pvt_runqueue_next_sched(
        if ( entry == NULL ) {
                *next_run = NULL;
                return NULL;
+       } else if ( entry->next_sched.tv_sec == 0 ) {
+               *next_run = NULL;
+               return NULL;
        } else {
                *next_run = &entry->next_sched;
                return entry;
@@ -127,22 +130,54 @@ ldap_pvt_runqueue_resched(
 
        LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
 
-       entry->next_sched.tv_sec = time( NULL ) + entry->interval.tv_sec;
+       if ( entry->interval.tv_sec ) {
+               entry->next_sched.tv_sec = time( NULL ) + entry->interval.tv_sec;
+       } else {
+               entry->next_sched.tv_sec = 0;
+       }
+
        if ( LDAP_STAILQ_EMPTY( &rq->task_list )) {
                LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
+       } else if ( entry->next_sched.tv_sec == 0 ) {
+               LDAP_STAILQ_INSERT_TAIL( &rq->task_list, entry, tnext );
        } else {
                prev = NULL;
                LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
-                       if ( e->next_sched.tv_sec > entry->next_sched.tv_sec ) {
+                       if ( e->next_sched.tv_sec == 0 ) {
+                               if ( prev == NULL ) {
+                                       LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
+                               } else {
+                                       LDAP_STAILQ_INSERT_AFTER( &rq->task_list, prev, entry, tnext );
+                               }
+                               break;
+                       } 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;
                        }
                        prev = e;
                }
        }
 }
 
+int
+ldap_pvt_runqueue_persistent_backload(
+       struct runqueue_s* rq
+)
+{
+       struct re_s* e;
+       int count = 0;
+
+       if ( !LDAP_STAILQ_EMPTY( &rq->task_list )) {
+               LDAP_STAILQ_FOREACH( e, &rq->task_list, tnext ) {
+                       if ( e->next_sched.tv_sec == 0 )
+                               count++;
+               }
+       }
+       return count;
+}
+
 #endif
index 2afa9767ab6e432d2ae07f215ae9c7c3bf9870fa..a0b8e92fc2580d872358a028a0f57dfbc2a9f37c 100644 (file)
@@ -1329,8 +1329,10 @@ slapd_daemon_task(
 
                ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
 
-               if ( !at )
-                       at = ldap_pvt_thread_pool_backload(&connection_pool);
+               if ( !at ) {
+                       at = ldap_pvt_thread_pool_backload(&connection_pool) -
+                                ldap_pvt_runqueue_persistent_backload( &syncrepl_rq );
+               }
 
                tvp = at ? &tv : NULL;