]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9642 Notify runner of any changes to the runqueue
authorOndřej Kuzník <ondra@mistotebe.net>
Mon, 13 Sep 2021 10:57:14 +0000 (11:57 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Wed, 15 Dec 2021 20:40:53 +0000 (20:40 +0000)
include/ldap_rq.h
libraries/libldap/rq.c
servers/slapd/daemon.c

index 4a92086a56b6c77c6e1e41a8c22c71fc7bb7bc4c..9970c6552bcf7b24ae6dd93fe3eeba45d6261b3f 100644 (file)
@@ -20,6 +20,9 @@
 
 LDAP_BEGIN_DECL
 
+struct runqueue_s;
+typedef void (ldap_pvt_rq_notify_cb) LDAP_P(( struct runqueue_s *rq ));
+
 typedef struct re_s {
        struct timeval next_sched;
        struct timeval interval;
@@ -36,6 +39,7 @@ typedef struct runqueue_s {
        LDAP_STAILQ_HEAD(l, re_s) task_list;
        LDAP_STAILQ_HEAD(rl, re_s) run_list;
        ldap_pvt_thread_mutex_t rq_mutex;
+       ldap_pvt_rq_notify_cb *rq_notify_cb;
 } runqueue_t;
 
 LDAP_F( struct re_s* )
index 877f3348443cccaecf0cef136953dd0c602a776e..200214383f89b1c8bb428177df0290b8e5a790a9 100644 (file)
@@ -59,6 +59,9 @@ ldap_pvt_runqueue_insert(
                entry->tname = tname;
                entry->tspec = tspec;
                LDAP_STAILQ_INSERT_HEAD( &rq->task_list, entry, tnext );
+               if ( rq->rq_notify_cb ) {
+                       rq->rq_notify_cb( rq );
+               }
        }
        return entry;
 }
@@ -95,6 +98,9 @@ ldap_pvt_runqueue_remove(
        assert( e == entry );
 
        LDAP_STAILQ_REMOVE( &rq->task_list, entry, re_s, tnext );
+       if ( rq->rq_notify_cb ) {
+               rq->rq_notify_cb( rq );
+       }
 
        LDAP_FREE( entry );
 }
@@ -123,6 +129,9 @@ ldap_pvt_runqueue_runtask(
 )
 {
        LDAP_STAILQ_INSERT_TAIL( &rq->run_list, entry, rnext );
+       if ( rq->rq_notify_cb ) {
+               rq->rq_notify_cb( rq );
+       }
 }
 
 void
@@ -132,6 +141,9 @@ ldap_pvt_runqueue_stoptask(
 )
 {
        LDAP_STAILQ_REMOVE( &rq->run_list, entry, re_s, rnext );
+       if ( rq->rq_notify_cb ) {
+               rq->rq_notify_cb( rq );
+       }
 }
 
 int
@@ -188,19 +200,24 @@ ldap_pvt_runqueue_resched(
                                } else {
                                        LDAP_STAILQ_INSERT_AFTER( &rq->task_list, prev, entry, tnext );
                                }
-                               return;
+                               goto done;
                        } 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 );
                                }
-                               return;
+                               goto done;
                        }
                        prev = e;
                }
                LDAP_STAILQ_INSERT_TAIL( &rq->task_list, entry, tnext );
        }
+
+done:
+       if ( rq->rq_notify_cb ) {
+               rq->rq_notify_cb( rq );
+       }
 }
 
 int
index 03345c6fa2e7a7b9301e33595a0232000fe1dbe7..bef59eed3b2e8cce6defa80cbe8965f80a1f7ba0 100644 (file)
@@ -79,11 +79,15 @@ int slap_inet4or6 = AF_UNSPEC;
 int slap_inet4or6 = AF_INET;
 #endif /* ! INETv6 */
 
+void slap_runqueue_notify( runqueue_t *rq );
+
 /* globals */
 time_t starttime;
 ber_socket_t dtblsize;
 slap_ssf_t local_ssf = LDAP_PVT_SASL_LOCAL_SSF;
-struct runqueue_s slapd_rq;
+struct runqueue_s slapd_rq = {
+    .rq_notify_cb = slap_runqueue_notify,
+};
 
 int slapd_daemon_threads = 1;
 int slapd_daemon_mask;
@@ -3572,6 +3576,12 @@ slap_wake_listener()
        WAKE_LISTENER(0,1);
 }
 
+void
+slap_runqueue_notify( runqueue_t *rq )
+{
+       slap_wake_listener();
+}
+
 /* return 0 on timeout, 1 on writer ready
  * -1 on general error
  */