From 19d4a698826aa9bd5fedc036b9e5cdcfa374502f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= Date: Mon, 13 Sep 2021 11:57:14 +0100 Subject: [PATCH] ITS#9642 Notify runner of any changes to the runqueue --- include/ldap_rq.h | 4 ++++ libraries/libldap/rq.c | 21 +++++++++++++++++++-- servers/slapd/daemon.c | 12 +++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/ldap_rq.h b/include/ldap_rq.h index 4a92086a56..9970c6552b 100644 --- a/include/ldap_rq.h +++ b/include/ldap_rq.h @@ -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* ) diff --git a/libraries/libldap/rq.c b/libraries/libldap/rq.c index 877f334844..200214383f 100644 --- a/libraries/libldap/rq.c +++ b/libraries/libldap/rq.c @@ -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 diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 03345c6fa2..bef59eed3b 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -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 */ -- 2.47.3