andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0031-Issue-4384-Separate-eventq-into-REALTIME-and-MONOTON.patch

be9751
From 69af412d42acccac660037e1f4026a6a6717634c Mon Sep 17 00:00:00 2001
be9751
From: Mark Reynolds <mreynolds@redhat.com>
be9751
Date: Thu, 17 Dec 2020 15:25:42 -0500
be9751
Subject: [PATCH 2/2] Issue 4384 - Separate eventq into REALTIME and MONOTONIC
be9751
be9751
Description:  The recent changes to the eventq "when" time changed
be9751
              internally from REALTIME to MONOTONIC, and this broke
be9751
              the API.  Create a new API for MONOTONIC clocks, and
be9751
              keep the original API intact for REALTIME clocks.
be9751
be9751
Relates:  https://github.com/389ds/389-ds-base/issues/4384
be9751
be9751
Reviewed by: firstyear(Thanks!)
be9751
---
be9751
 Makefile.am                                   |   1 +
be9751
 docs/slapi.doxy.in                            |   1 -
be9751
 ldap/servers/plugins/chainingdb/cb_instance.c |   6 +-
be9751
 ldap/servers/plugins/dna/dna.c                |   4 +-
be9751
 .../plugins/replication/repl5_backoff.c       |  12 +-
be9751
 .../plugins/replication/repl5_connection.c    |  10 +-
be9751
 .../plugins/replication/repl5_mtnode_ext.c    |   4 +-
be9751
 .../plugins/replication/repl5_replica.c       |  24 +-
be9751
 .../plugins/replication/repl5_schedule.c      |   4 +-
be9751
 .../plugins/replication/windows_connection.c  |  12 +-
be9751
 .../replication/windows_inc_protocol.c        |   7 +-
be9751
 ldap/servers/plugins/retrocl/retrocl_trim.c   |  10 +-
be9751
 ldap/servers/slapd/daemon.c                   |   3 +-
be9751
 ldap/servers/slapd/eventq-deprecated.c        | 483 ++++++++++++++++++
be9751
 ldap/servers/slapd/eventq.c                   | 236 ++++-----
be9751
 ldap/servers/slapd/main.c                     |  18 +-
be9751
 ldap/servers/slapd/proto-slap.h               |   6 +-
be9751
 ldap/servers/slapd/slapi-plugin.h             |  62 ++-
be9751
 ldap/servers/slapd/slapi2runtime.c            |  23 +-
be9751
 ldap/servers/slapd/snmp_collator.c            |   7 +-
be9751
 ldap/servers/slapd/task.c                     |   2 +-
be9751
 ldap/servers/slapd/uuid.c                     |   3 +-
be9751
 22 files changed, 750 insertions(+), 188 deletions(-)
be9751
 create mode 100644 ldap/servers/slapd/eventq-deprecated.c
be9751
be9751
diff --git a/Makefile.am b/Makefile.am
be9751
index f7bf1c44c..ece1ad41a 100644
be9751
--- a/Makefile.am
be9751
+++ b/Makefile.am
be9751
@@ -1408,6 +1408,7 @@ libslapd_la_SOURCES = ldap/servers/slapd/add.c \
be9751
 	ldap/servers/slapd/entrywsi.c \
be9751
 	ldap/servers/slapd/errormap.c \
be9751
 	ldap/servers/slapd/eventq.c \
be9751
+	ldap/servers/slapd/eventq-deprecated.c \
be9751
 	ldap/servers/slapd/factory.c \
be9751
 	ldap/servers/slapd/features.c \
be9751
 	ldap/servers/slapd/fileio.c \
be9751
diff --git a/docs/slapi.doxy.in b/docs/slapi.doxy.in
be9751
index b1e4810ab..1cafc50ce 100644
be9751
--- a/docs/slapi.doxy.in
be9751
+++ b/docs/slapi.doxy.in
be9751
@@ -759,7 +759,6 @@ WARN_LOGFILE           =
be9751
 # Note: If this tag is empty the current directory is searched.
be9751
 
be9751
 INPUT                  = src/libsds/include/sds.h \
be9751
-                         docs/job-safety.md \
be9751
                          # ldap/servers/slapd/slapi-plugin.h \
be9751
 
be9751
 # This tag can be used to specify the character encoding of the source files
be9751
diff --git a/ldap/servers/plugins/chainingdb/cb_instance.c b/ldap/servers/plugins/chainingdb/cb_instance.c
be9751
index bc1864c1a..7fd85deb0 100644
be9751
--- a/ldap/servers/plugins/chainingdb/cb_instance.c
be9751
+++ b/ldap/servers/plugins/chainingdb/cb_instance.c
be9751
@@ -217,7 +217,7 @@ cb_instance_free(cb_backend_instance *inst)
be9751
         slapi_rwlock_wrlock(inst->rwl_config_lock);
be9751
 
be9751
         if (inst->eq_ctx != NULL) {
be9751
-            slapi_eq_cancel(inst->eq_ctx);
be9751
+            slapi_eq_cancel_rel(inst->eq_ctx);
be9751
             inst->eq_ctx = NULL;
be9751
         }
be9751
 
be9751
@@ -1947,8 +1947,8 @@ cb_instance_add_config_callback(Slapi_PBlock *pb __attribute__((unused)),
be9751
          * we can't call recursively into the DSE to do more adds, they'll
be9751
          * silently fail.  instead, schedule the adds to happen in 1 second.
be9751
          */
be9751
-        inst->eq_ctx = slapi_eq_once(cb_instance_add_monitor_later, (void *)inst,
be9751
-                                     slapi_current_rel_time_t() + 1);
be9751
+        inst->eq_ctx = slapi_eq_once_rel(cb_instance_add_monitor_later, (void *)inst,
be9751
+                                         slapi_current_rel_time_t() + 1);
be9751
     }
be9751
 
be9751
     /* Get the list of operational attrs defined in the schema */
be9751
diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
be9751
index 1cb54580b..b46edfcbb 100644
be9751
--- a/ldap/servers/plugins/dna/dna.c
be9751
+++ b/ldap/servers/plugins/dna/dna.c
be9751
@@ -688,7 +688,7 @@ dna_close(Slapi_PBlock *pb __attribute__((unused)))
be9751
     slapi_log_err(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
be9751
                   "--> dna_close\n");
be9751
 
be9751
-    slapi_eq_cancel(eq_ctx);
be9751
+    slapi_eq_cancel_rel(eq_ctx);
be9751
     dna_delete_config(NULL);
be9751
     slapi_ch_free((void **)&dna_global_config);
be9751
     slapi_destroy_rwlock(g_dna_cache_lock);
be9751
@@ -908,7 +908,7 @@ dna_load_plugin_config(Slapi_PBlock *pb, int use_eventq)
be9751
          * starting up  would cause the change to not
be9751
          * get changelogged. */
be9751
         now = slapi_current_rel_time_t();
be9751
-        eq_ctx = slapi_eq_once(dna_update_config_event, NULL, now + 30);
be9751
+        eq_ctx = slapi_eq_once_rel(dna_update_config_event, NULL, now + 30);
be9751
     } else {
be9751
         dna_update_config_event(0, NULL);
be9751
     }
be9751
diff --git a/ldap/servers/plugins/replication/repl5_backoff.c b/ldap/servers/plugins/replication/repl5_backoff.c
be9751
index 40ec75dd7..8c851beb2 100644
be9751
--- a/ldap/servers/plugins/replication/repl5_backoff.c
be9751
+++ b/ldap/servers/plugins/replication/repl5_backoff.c
be9751
@@ -99,7 +99,7 @@ backoff_reset(Backoff_Timer *bt, slapi_eq_fn_t callback, void *callback_data)
be9751
     bt->callback_arg = callback_data;
be9751
     /* Cancel any pending events in the event queue */
be9751
     if (NULL != bt->pending_event) {
be9751
-        slapi_eq_cancel(bt->pending_event);
be9751
+        slapi_eq_cancel_rel(bt->pending_event);
be9751
         bt->pending_event = NULL;
be9751
     }
be9751
     /* Compute the first fire time */
be9751
@@ -112,8 +112,8 @@ backoff_reset(Backoff_Timer *bt, slapi_eq_fn_t callback, void *callback_data)
be9751
     /* Schedule the callback */
be9751
     bt->last_fire_time = slapi_current_rel_time_t();
be9751
     return_value = bt->last_fire_time + bt->next_interval;
be9751
-    bt->pending_event = slapi_eq_once(bt->callback, bt->callback_arg,
be9751
-                                      return_value);
be9751
+    bt->pending_event = slapi_eq_once_rel(bt->callback, bt->callback_arg,
be9751
+                                          return_value);
be9751
     PR_Unlock(bt->lock);
be9751
     return return_value;
be9751
 }
be9751
@@ -159,8 +159,8 @@ backoff_step(Backoff_Timer *bt)
be9751
         /* Schedule the callback, if any */
be9751
         bt->last_fire_time += previous_interval;
be9751
         return_value = bt->last_fire_time + bt->next_interval;
be9751
-        bt->pending_event = slapi_eq_once(bt->callback, bt->callback_arg,
be9751
-                                          return_value);
be9751
+        bt->pending_event = slapi_eq_once_rel(bt->callback, bt->callback_arg,
be9751
+                                              return_value);
be9751
     }
be9751
     PR_Unlock(bt->lock);
be9751
     return return_value;
be9751
@@ -196,7 +196,7 @@ backoff_delete(Backoff_Timer **btp)
be9751
     PR_Lock(bt->lock);
be9751
     /* Cancel any pending events in the event queue */
be9751
     if (NULL != bt->pending_event) {
be9751
-        slapi_eq_cancel(bt->pending_event);
be9751
+        slapi_eq_cancel_rel(bt->pending_event);
be9751
     }
be9751
     PR_Unlock(bt->lock);
be9751
     PR_DestroyLock(bt->lock);
be9751
diff --git a/ldap/servers/plugins/replication/repl5_connection.c b/ldap/servers/plugins/replication/repl5_connection.c
be9751
index bc9ca424b..2dd74f9e7 100644
be9751
--- a/ldap/servers/plugins/replication/repl5_connection.c
be9751
+++ b/ldap/servers/plugins/replication/repl5_connection.c
be9751
@@ -272,7 +272,7 @@ conn_delete(Repl_Connection *conn)
be9751
     PR_ASSERT(NULL != conn);
be9751
     PR_Lock(conn->lock);
be9751
     if (conn->linger_active) {
be9751
-        if (slapi_eq_cancel(conn->linger_event) == 1) {
be9751
+        if (slapi_eq_cancel_rel(conn->linger_event) == 1) {
be9751
             /* Event was found and cancelled. Destroy the connection object. */
be9751
             destroy_it = PR_TRUE;
be9751
         } else {
be9751
@@ -961,7 +961,7 @@ conn_cancel_linger(Repl_Connection *conn)
be9751
                       "conn_cancel_linger - %s - Canceling linger on the connection\n",
be9751
                       agmt_get_long_name(conn->agmt));
be9751
         conn->linger_active = PR_FALSE;
be9751
-        if (slapi_eq_cancel(conn->linger_event) == 1) {
be9751
+        if (slapi_eq_cancel_rel(conn->linger_event) == 1) {
be9751
             conn->refcnt--;
be9751
         }
be9751
         conn->linger_event = NULL;
be9751
@@ -1030,7 +1030,7 @@ conn_start_linger(Repl_Connection *conn)
be9751
                       agmt_get_long_name(conn->agmt));
be9751
     } else {
be9751
         conn->linger_active = PR_TRUE;
be9751
-        conn->linger_event = slapi_eq_once(linger_timeout, conn, now + conn->linger_time);
be9751
+        conn->linger_event = slapi_eq_once_rel(linger_timeout, conn, now + conn->linger_time);
be9751
         conn->status = STATUS_LINGERING;
be9751
     }
be9751
     PR_Unlock(conn->lock);
be9751
@@ -1990,7 +1990,7 @@ repl5_start_debug_timeout(int *setlevel)
be9751
     Slapi_Eq_Context eqctx = 0;
be9751
     if (s_debug_timeout && s_debug_level) {
be9751
         time_t now = slapi_current_rel_time_t();
be9751
-        eqctx = slapi_eq_once(repl5_debug_timeout_callback, setlevel,
be9751
+        eqctx = slapi_eq_once_rel(repl5_debug_timeout_callback, setlevel,
be9751
                               s_debug_timeout + now);
be9751
     }
be9751
     return eqctx;
be9751
@@ -2002,7 +2002,7 @@ repl5_stop_debug_timeout(Slapi_Eq_Context eqctx, int *setlevel)
be9751
     char buf[20];
be9751
 
be9751
     if (eqctx && !*setlevel) {
be9751
-        (void)slapi_eq_cancel(eqctx);
be9751
+        (void)slapi_eq_cancel_rel(eqctx);
be9751
     }
be9751
 
be9751
     if (s_debug_timeout && s_debug_level && *setlevel) {
be9751
diff --git a/ldap/servers/plugins/replication/repl5_mtnode_ext.c b/ldap/servers/plugins/replication/repl5_mtnode_ext.c
be9751
index 82e230958..2967a47f8 100644
be9751
--- a/ldap/servers/plugins/replication/repl5_mtnode_ext.c
be9751
+++ b/ldap/servers/plugins/replication/repl5_mtnode_ext.c
be9751
@@ -82,8 +82,8 @@ multimaster_mtnode_construct_replicas()
be9751
                 }
be9751
             }
be9751
             /* Wait a few seconds for everything to startup before resuming any replication tasks */
be9751
-            slapi_eq_once(replica_check_for_tasks, (void *)replica_get_root(r),
be9751
-                          slapi_current_rel_time_t() + 5);
be9751
+            slapi_eq_once_rel(replica_check_for_tasks, (void *)replica_get_root(r),
be9751
+                              slapi_current_rel_time_t() + 5);
be9751
         }
be9751
     }
be9751
 }
be9751
diff --git a/ldap/servers/plugins/replication/repl5_replica.c b/ldap/servers/plugins/replication/repl5_replica.c
be9751
index c1d376c72..7102e0606 100644
be9751
--- a/ldap/servers/plugins/replication/repl5_replica.c
be9751
+++ b/ldap/servers/plugins/replication/repl5_replica.c
be9751
@@ -231,17 +231,17 @@ replica_new_from_entry(Slapi_Entry *e, char *errortext, PRBool is_add_operation,
be9751
     /* ONREPL - the state update can occur before the entry is added to the DIT.
be9751
        In that case the updated would fail but nothing bad would happen. The next
be9751
        scheduled update would save the state */
be9751
-    r->repl_eqcxt_rs = slapi_eq_repeat(replica_update_state, r->repl_name,
be9751
-                                       slapi_current_rel_time_t() + START_UPDATE_DELAY, RUV_SAVE_INTERVAL);
be9751
+    r->repl_eqcxt_rs = slapi_eq_repeat_rel(replica_update_state, r->repl_name,
be9751
+                                           slapi_current_rel_time_t() + START_UPDATE_DELAY, RUV_SAVE_INTERVAL);
be9751
 
be9751
     if (r->tombstone_reap_interval > 0) {
be9751
         /*
be9751
          * Reap Tombstone should be started some time after the plugin started.
be9751
          * This will allow the server to fully start before consuming resources.
be9751
          */
be9751
-        r->repl_eqcxt_tr = slapi_eq_repeat(eq_cb_reap_tombstones, r->repl_name,
be9751
-                                           slapi_current_rel_time_t() + r->tombstone_reap_interval,
be9751
-                                           1000 * r->tombstone_reap_interval);
be9751
+        r->repl_eqcxt_tr = slapi_eq_repeat_rel(eq_cb_reap_tombstones, r->repl_name,
be9751
+                                               slapi_current_rel_time_t() + r->tombstone_reap_interval,
be9751
+                                               1000 * r->tombstone_reap_interval);
be9751
     }
be9751
 
be9751
 done:
be9751
@@ -303,12 +303,12 @@ replica_destroy(void **arg)
be9751
      */
be9751
 
be9751
     if (r->repl_eqcxt_rs) {
be9751
-        slapi_eq_cancel(r->repl_eqcxt_rs);
be9751
+        slapi_eq_cancel_rel(r->repl_eqcxt_rs);
be9751
         r->repl_eqcxt_rs = NULL;
be9751
     }
be9751
 
be9751
     if (r->repl_eqcxt_tr) {
be9751
-        slapi_eq_cancel(r->repl_eqcxt_tr);
be9751
+        slapi_eq_cancel_rel(r->repl_eqcxt_tr);
be9751
         r->repl_eqcxt_tr = NULL;
be9751
     }
be9751
 
be9751
@@ -1511,14 +1511,14 @@ replica_set_enabled(Replica *r, PRBool enable)
be9751
     if (enable) {
be9751
         if (r->repl_eqcxt_rs == NULL) /* event is not already registered */
be9751
         {
be9751
-            r->repl_eqcxt_rs = slapi_eq_repeat(replica_update_state, r->repl_name,
be9751
-                                               slapi_current_rel_time_t() + START_UPDATE_DELAY, RUV_SAVE_INTERVAL);
be9751
+            r->repl_eqcxt_rs = slapi_eq_repeat_rel(replica_update_state, r->repl_name,
be9751
+                                                   slapi_current_rel_time_t() + START_UPDATE_DELAY, RUV_SAVE_INTERVAL);
be9751
         }
be9751
     } else /* disable */
be9751
     {
be9751
         if (r->repl_eqcxt_rs) /* event is still registerd */
be9751
         {
be9751
-            slapi_eq_cancel(r->repl_eqcxt_rs);
be9751
+            slapi_eq_cancel_rel(r->repl_eqcxt_rs);
be9751
             r->repl_eqcxt_rs = NULL;
be9751
         }
be9751
     }
be9751
@@ -3628,7 +3628,7 @@ replica_set_tombstone_reap_interval(Replica *r, long interval)
be9751
     if (interval > 0 && r->repl_eqcxt_tr && r->tombstone_reap_interval != interval) {
be9751
         int found;
be9751
 
be9751
-        found = slapi_eq_cancel(r->repl_eqcxt_tr);
be9751
+        found = slapi_eq_cancel_rel(r->repl_eqcxt_tr);
be9751
         slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
be9751
                       "replica_set_tombstone_reap_interval - tombstone_reap event (interval=%" PRId64 ") was %s\n",
be9751
                       r->tombstone_reap_interval, (found ? "cancelled" : "not found"));
be9751
@@ -3636,7 +3636,7 @@ replica_set_tombstone_reap_interval(Replica *r, long interval)
be9751
     }
be9751
     r->tombstone_reap_interval = interval;
be9751
     if (interval > 0 && r->repl_eqcxt_tr == NULL) {
be9751
-        r->repl_eqcxt_tr = slapi_eq_repeat(eq_cb_reap_tombstones, r->repl_name,
be9751
+        r->repl_eqcxt_tr = slapi_eq_repeat_rel(eq_cb_reap_tombstones, r->repl_name,
be9751
                                            slapi_current_rel_time_t() + r->tombstone_reap_interval,
be9751
                                            1000 * r->tombstone_reap_interval);
be9751
         slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
be9751
diff --git a/ldap/servers/plugins/replication/repl5_schedule.c b/ldap/servers/plugins/replication/repl5_schedule.c
be9751
index 9539f4031..ca42df561 100644
be9751
--- a/ldap/servers/plugins/replication/repl5_schedule.c
be9751
+++ b/ldap/servers/plugins/replication/repl5_schedule.c
be9751
@@ -550,7 +550,7 @@ schedule_window_state_change_event(Schedule *sch)
be9751
         wakeup_time = PRTime2time_t(tm);
be9751
 
be9751
         /* schedule the event */
be9751
-        sch->pending_event = slapi_eq_once(window_state_changed, sch, wakeup_time);
be9751
+        sch->pending_event = slapi_eq_once_rel(window_state_changed, sch, wakeup_time);
be9751
 
be9751
         timestr = get_timestring(&wakeup_time);
be9751
         slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "%s: Update window will %s at %s\n",
be9751
@@ -593,7 +593,7 @@ static void
be9751
 unschedule_window_state_change_event(Schedule *sch)
be9751
 {
be9751
     if (sch->pending_event) {
be9751
-        slapi_eq_cancel(sch->pending_event);
be9751
+        slapi_eq_cancel_rel(sch->pending_event);
be9751
         sch->pending_event = NULL;
be9751
     }
be9751
 }
be9751
diff --git a/ldap/servers/plugins/replication/windows_connection.c b/ldap/servers/plugins/replication/windows_connection.c
be9751
index ce0662544..5eca5fad1 100644
be9751
--- a/ldap/servers/plugins/replication/windows_connection.c
be9751
+++ b/ldap/servers/plugins/replication/windows_connection.c
be9751
@@ -204,7 +204,7 @@ windows_conn_delete(Repl_Connection *conn)
be9751
     PR_ASSERT(NULL != conn);
be9751
     PR_Lock(conn->lock);
be9751
     if (conn->linger_active) {
be9751
-        if (slapi_eq_cancel(conn->linger_event) == 1) {
be9751
+        if (slapi_eq_cancel_rel(conn->linger_event) == 1) {
be9751
             /* Event was found and cancelled. Destroy the connection object. */
be9751
             PR_Unlock(conn->lock);
be9751
             destroy_it = PR_TRUE;
be9751
@@ -1052,7 +1052,7 @@ windows_conn_cancel_linger(Repl_Connection *conn)
be9751
                       "windows_conn_cancel_linger - %s: Cancelling linger on the connection\n",
be9751
                       agmt_get_long_name(conn->agmt));
be9751
         conn->linger_active = PR_FALSE;
be9751
-        if (slapi_eq_cancel(conn->linger_event) == 1) {
be9751
+        if (slapi_eq_cancel_rel(conn->linger_event) == 1) {
be9751
             conn->refcnt--;
be9751
         }
be9751
         conn->linger_event = NULL;
be9751
@@ -1129,7 +1129,7 @@ windows_conn_start_linger(Repl_Connection *conn)
be9751
                       agmt_get_long_name(conn->agmt));
be9751
     } else {
be9751
         conn->linger_active = PR_TRUE;
be9751
-        conn->linger_event = slapi_eq_once(linger_timeout, conn, now + conn->linger_time);
be9751
+        conn->linger_event = slapi_eq_once_rel(linger_timeout, conn, now + conn->linger_time);
be9751
         conn->status = STATUS_LINGERING;
be9751
     }
be9751
     PR_Unlock(conn->lock);
be9751
@@ -1822,8 +1822,8 @@ repl5_start_debug_timeout(int *setlevel)
be9751
 
be9751
     if (s_debug_timeout && s_debug_level) {
be9751
         time_t now = time(NULL);
be9751
-        eqctx = slapi_eq_once(repl5_debug_timeout_callback, setlevel,
be9751
-                              s_debug_timeout + now);
be9751
+        eqctx = slapi_eq_once_rel(repl5_debug_timeout_callback, setlevel,
be9751
+                                  s_debug_timeout + now);
be9751
     }
be9751
     slapi_log_err(SLAPI_LOG_TRACE, windows_repl_plugin_name, "<= repl5_start_debug_timeout\n");
be9751
     return eqctx;
be9751
@@ -1837,7 +1837,7 @@ repl5_stop_debug_timeout(Slapi_Eq_Context eqctx, int *setlevel)
be9751
     slapi_log_err(SLAPI_LOG_TRACE, windows_repl_plugin_name, "=> repl5_stop_debug_timeout\n");
be9751
 
be9751
     if (eqctx && !*setlevel) {
be9751
-        (void)slapi_eq_cancel(eqctx);
be9751
+        (void)slapi_eq_cancel_rel(eqctx);
be9751
     }
be9751
 
be9751
     if (s_debug_timeout && s_debug_level && *setlevel) {
be9751
diff --git a/ldap/servers/plugins/replication/windows_inc_protocol.c b/ldap/servers/plugins/replication/windows_inc_protocol.c
be9751
index 3d548e5ed..c07a8180a 100644
be9751
--- a/ldap/servers/plugins/replication/windows_inc_protocol.c
be9751
+++ b/ldap/servers/plugins/replication/windows_inc_protocol.c
be9751
@@ -132,7 +132,7 @@ windows_inc_delete(Private_Repl_Protocol **prpp)
be9751
     slapi_log_err(SLAPI_LOG_TRACE, windows_repl_plugin_name, "=> windows_inc_delete\n");
be9751
     /* First, stop the protocol if it isn't already stopped */
be9751
     /* Then, delete all resources used by the protocol */
be9751
-    rc = slapi_eq_cancel(dirsync);
be9751
+    rc = slapi_eq_cancel_rel(dirsync);
be9751
     slapi_log_err(SLAPI_LOG_REPL, windows_repl_plugin_name,
be9751
                   "windows_inc_delete - dirsync: %p, rval: %d\n", dirsync, rc);
be9751
     /* if backoff is set, delete it (from EQ, as well) */
be9751
@@ -324,12 +324,13 @@ windows_inc_run(Private_Repl_Protocol *prp)
be9751
             if (interval != current_interval) {
be9751
                 current_interval = interval;
be9751
                 if (dirsync) {
be9751
-                    int rc = slapi_eq_cancel(dirsync);
be9751
+                    int rc = slapi_eq_cancel_rel(dirsync);
be9751
                     slapi_log_err(SLAPI_LOG_REPL, windows_repl_plugin_name,
be9751
                                   "windows_inc_run - Cancelled dirsync: %p, rval: %d\n",
be9751
                                   dirsync, rc);
be9751
                 }
be9751
-                dirsync = slapi_eq_repeat(periodic_dirsync, (void *)prp, (time_t)0, interval);
be9751
+                dirsync = slapi_eq_repeat_rel(periodic_dirsync, (void *)prp,
be9751
+                                              slapi_current_rel_time_t(), interval);
be9751
                 slapi_log_err(SLAPI_LOG_REPL, windows_repl_plugin_name,
be9751
                               "windows_inc_run - New dirsync: %p\n", dirsync);
be9751
             }
be9751
diff --git a/ldap/servers/plugins/retrocl/retrocl_trim.c b/ldap/servers/plugins/retrocl/retrocl_trim.c
be9751
index a3e16c4e1..12a395210 100644
be9751
--- a/ldap/servers/plugins/retrocl/retrocl_trim.c
be9751
+++ b/ldap/servers/plugins/retrocl/retrocl_trim.c
be9751
@@ -460,10 +460,10 @@ retrocl_init_trimming(void)
be9751
     ts.ts_s_initialized = 1;
be9751
     retrocl_trimming = 1;
be9751
 
be9751
-    retrocl_trim_ctx = slapi_eq_repeat(retrocl_housekeeping,
be9751
-                                       NULL, (time_t)0,
be9751
-                                       /* in milliseconds */
be9751
-                                       trim_interval * 1000);
be9751
+    retrocl_trim_ctx = slapi_eq_repeat_rel(retrocl_housekeeping,
be9751
+                                           NULL, (time_t)0,
be9751
+                                           /* in milliseconds */
be9751
+                                           trim_interval * 1000);
be9751
 }
be9751
 
be9751
 /*
be9751
@@ -487,7 +487,7 @@ retrocl_stop_trimming(void)
be9751
          */
be9751
         retrocl_trimming = 0;
be9751
         if (retrocl_trim_ctx) {
be9751
-            slapi_eq_cancel(retrocl_trim_ctx);
be9751
+            slapi_eq_cancel_rel(retrocl_trim_ctx);
be9751
             retrocl_trim_ctx = NULL;
be9751
         }
be9751
         PR_DestroyLock(ts.ts_s_trim_mutex);
be9751
diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c
be9751
index 0071ed86a..7681e88ea 100644
be9751
--- a/ldap/servers/slapd/daemon.c
be9751
+++ b/ldap/servers/slapd/daemon.c
be9751
@@ -1240,7 +1240,8 @@ slapd_daemon(daemon_ports_t *ports)
be9751
     slapi_log_err(SLAPI_LOG_TRACE, "slapd_daemon",
be9751
                   "slapd shutting down - waiting for backends to close down\n");
be9751
 
be9751
-    eq_stop();
be9751
+    eq_stop(); /* deprecated */
be9751
+    eq_stop_rel();
be9751
     if (!in_referral_mode) {
be9751
         task_shutdown();
be9751
         uniqueIDGenCleanup();
be9751
diff --git a/ldap/servers/slapd/eventq-deprecated.c b/ldap/servers/slapd/eventq-deprecated.c
be9751
new file mode 100644
be9751
index 000000000..71a7bf8f5
be9751
--- /dev/null
be9751
+++ b/ldap/servers/slapd/eventq-deprecated.c
be9751
@@ -0,0 +1,483 @@
be9751
+/** BEGIN COPYRIGHT BLOCK
be9751
+ * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
be9751
+ * Copyright (C) 2020 Red Hat, Inc.
be9751
+ * All rights reserved.
be9751
+ *
be9751
+ * License: GPL (version 3 or any later version).
be9751
+ * See LICENSE for details.
be9751
+ * END COPYRIGHT BLOCK **/
be9751
+
be9751
+#ifdef HAVE_CONFIG_H
be9751
+#include <config.h>
be9751
+#endif
be9751
+
be9751
+
be9751
+/* ********************************************************
be9751
+eventq-deprecated.c - Event queue/scheduling system.
be9751
+
be9751
+There are 3 publicly-accessible entry points:
be9751
+
be9751
+slapi_eq_once(): cause an event to happen exactly once
be9751
+slapi_eq_repeat(): cause an event to happen repeatedly
be9751
+slapi_eq_cancel(): cancel a pending event
be9751
+
be9751
+There is also an initialization point which must be
be9751
+called by the server to initialize the event queue system:
be9751
+eq_start(), and an entry point used to shut down the system:
be9751
+eq_stop().
be9751
+
be9751
+These functions are now deprecated in favor of the functions
be9751
+in eventq.c which use MONOTONIC clocks instead of REALTIME
be9751
+clocks.
be9751
+*********************************************************** */
be9751
+
be9751
+#include "slap.h"
be9751
+#include "prlock.h"
be9751
+#include "prcvar.h"
be9751
+#include "prinit.h"
be9751
+
be9751
+/*
be9751
+ * Private definition of slapi_eq_context. Only this
be9751
+ * module (eventq.c) should know about the layout of
be9751
+ * this structure.
be9751
+ */
be9751
+typedef struct _slapi_eq_context
be9751
+{
be9751
+    time_t ec_when;
be9751
+    time_t ec_interval;
be9751
+    slapi_eq_fn_t ec_fn;
be9751
+    void *ec_arg;
be9751
+    Slapi_Eq_Context ec_id;
be9751
+    struct _slapi_eq_context *ec_next;
be9751
+} slapi_eq_context;
be9751
+
be9751
+/*
be9751
+ * Definition of the event queue.
be9751
+ */
be9751
+typedef struct _event_queue
be9751
+{
be9751
+    PRLock *eq_lock;
be9751
+    PRCondVar *eq_cv;
be9751
+    slapi_eq_context *eq_queue;
be9751
+} event_queue;
be9751
+
be9751
+/*
be9751
+ * The event queue itself.
be9751
+ */
be9751
+static event_queue eqs = {0};
be9751
+static event_queue *eq = &eqs;
be9751
+
be9751
+/*
be9751
+ * Thread ID of the main thread loop
be9751
+ */
be9751
+static PRThread *eq_loop_tid = NULL;
be9751
+
be9751
+/*
be9751
+ * Flags used to control startup/shutdown of the event queue
be9751
+ */
be9751
+static int eq_running = 0;
be9751
+static int eq_stopped = 0;
be9751
+static int eq_initialized = 0;
be9751
+PRLock *ss_lock = NULL;
be9751
+PRCondVar *ss_cv = NULL;
be9751
+PRCallOnceType init_once = {0};
be9751
+
be9751
+/* Forward declarations */
be9751
+static slapi_eq_context *eq_new(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval);
be9751
+static void eq_enqueue(slapi_eq_context *newec);
be9751
+static slapi_eq_context *eq_dequeue(time_t now);
be9751
+static PRStatus eq_create(void);
be9751
+
be9751
+
be9751
+/* ******************************************************** */
be9751
+
be9751
+
be9751
+/*
be9751
+ * slapi_eq_once: cause an event to happen exactly once.
be9751
+ *
be9751
+ * Arguments:
be9751
+ *  fn: the function to call
be9751
+ *  arg: an argument to pass to the called function
be9751
+ *  when: the time that the function should be called
be9751
+ * Returns:
be9751
+ *  slapi_eq_context - a handle to an opaque object which
be9751
+ *  the caller can use to refer to this particular scheduled
be9751
+ *  event.
be9751
+ */
be9751
+Slapi_Eq_Context
be9751
+slapi_eq_once(slapi_eq_fn_t fn, void *arg, time_t when)
be9751
+{
be9751
+    slapi_eq_context *tmp;
be9751
+    PR_ASSERT(eq_initialized);
be9751
+    if (!eq_stopped) {
be9751
+
be9751
+        Slapi_Eq_Context id;
be9751
+
be9751
+        tmp = eq_new(fn, arg, when, 0UL);
be9751
+        id = tmp->ec_id;
be9751
+
be9751
+        eq_enqueue(tmp);
be9751
+
be9751
+        /* After this point, <tmp> may have      */
be9751
+        /* been freed, depending on the thread   */
be9751
+        /* scheduling. Too bad             */
be9751
+
be9751
+        slapi_log_err(SLAPI_LOG_HOUSE, NULL,
be9751
+                      "added one-time event id %p at time %ld\n",
be9751
+                      id, when);
be9751
+        return (id);
be9751
+    }
be9751
+    return NULL; /* JCM - Not sure if this should be 0 or something else. */
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * slapi_eq_repeat: cause an event to happen repeatedly.
be9751
+ *
be9751
+ * Arguments:
be9751
+ *  fn: the function to call
be9751
+ *  arg: an argument to pass to the called function
be9751
+ *  when: the time that the function should first be called
be9751
+ *  interval: the amount of time (in milliseconds) between
be9751
+ *            successive calls to the function
be9751
+ * Returns:
be9751
+ *  slapi_eq_context - a handle to an opaque object which
be9751
+ *  the caller can use to refer to this particular scheduled
be9751
+ */
be9751
+Slapi_Eq_Context
be9751
+slapi_eq_repeat(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval)
be9751
+{
be9751
+    slapi_eq_context *tmp;
be9751
+    PR_ASSERT(eq_initialized);
be9751
+    if (!eq_stopped) {
be9751
+        tmp = eq_new(fn, arg, when, interval);
be9751
+        eq_enqueue(tmp);
be9751
+        slapi_log_err(SLAPI_LOG_HOUSE, NULL,
be9751
+                      "added repeating event id %p at time %ld, interval %lu\n",
be9751
+                      tmp->ec_id, when, interval);
be9751
+        return (tmp->ec_id);
be9751
+    }
be9751
+    return NULL; /* JCM - Not sure if this should be 0 or something else. */
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * slapi_eq_cancel: cancel a pending event.
be9751
+ * Arguments:
be9751
+ *  ctx: the context of the event which should be de-scheduled
be9751
+ */
be9751
+int
be9751
+slapi_eq_cancel(Slapi_Eq_Context ctx)
be9751
+{
be9751
+    slapi_eq_context **p, *tmp = NULL;
be9751
+    int found = 0;
be9751
+
be9751
+    PR_ASSERT(eq_initialized);
be9751
+    if (!eq_stopped) {
be9751
+        PR_Lock(eq->eq_lock);
be9751
+        p = &(eq->eq_queue);
be9751
+        while (!found && *p != NULL) {
be9751
+            if ((*p)->ec_id == ctx) {
be9751
+                tmp = *p;
be9751
+                *p = (*p)->ec_next;
be9751
+                slapi_ch_free((void **)&tmp);
be9751
+                found = 1;
be9751
+            } else {
be9751
+                p = &((*p)->ec_next);
be9751
+            }
be9751
+        }
be9751
+        PR_Unlock(eq->eq_lock);
be9751
+    }
be9751
+    slapi_log_err(SLAPI_LOG_HOUSE, NULL,
be9751
+                  "cancellation of event id %p requested: %s\n",
be9751
+                  ctx, found ? "cancellation succeeded" : "event not found");
be9751
+    return found;
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * Construct a new ec structure
be9751
+ */
be9751
+static slapi_eq_context *
be9751
+eq_new(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval)
be9751
+{
be9751
+    slapi_eq_context *retptr = (slapi_eq_context *)slapi_ch_calloc(1, sizeof(slapi_eq_context));
be9751
+
be9751
+    retptr->ec_fn = fn;
be9751
+    retptr->ec_arg = arg;
be9751
+    /*
be9751
+     * retptr->ec_when = when < now ? now : when;
be9751
+     * we used to amke this check, but it make no sense: when queued, if when
be9751
+     * has expired, we'll be executed anyway. save the cycles, and just set
be9751
+     * ec_when.
be9751
+     */
be9751
+    retptr->ec_when = when;
be9751
+    retptr->ec_interval = interval == 0UL ? 0UL : (interval + 999) / 1000;
be9751
+    retptr->ec_id = (Slapi_Eq_Context)retptr;
be9751
+    return retptr;
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * Add a new event to the event queue.
be9751
+ */
be9751
+static void
be9751
+eq_enqueue(slapi_eq_context *newec)
be9751
+{
be9751
+    slapi_eq_context **p;
be9751
+
be9751
+    PR_ASSERT(NULL != newec);
be9751
+    PR_Lock(eq->eq_lock);
be9751
+    /* Insert <newec> in order (sorted by start time) in the list */
be9751
+    for (p = &(eq->eq_queue); *p != NULL; p = &((*p)->ec_next)) {
be9751
+        if ((*p)->ec_when > newec->ec_when) {
be9751
+            break;
be9751
+        }
be9751
+    }
be9751
+    if (NULL != *p) {
be9751
+        newec->ec_next = *p;
be9751
+    } else {
be9751
+        newec->ec_next = NULL;
be9751
+    }
be9751
+    *p = newec;
be9751
+    PR_NotifyCondVar(eq->eq_cv); /* wake up scheduler thread */
be9751
+    PR_Unlock(eq->eq_lock);
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * If there is an event in the queue scheduled at time
be9751
+ * <now> or before, dequeue it and return a pointer
be9751
+ * to it. Otherwise, return NULL.
be9751
+ */
be9751
+static slapi_eq_context *
be9751
+eq_dequeue(time_t now)
be9751
+{
be9751
+    slapi_eq_context *retptr = NULL;
be9751
+
be9751
+    PR_Lock(eq->eq_lock);
be9751
+    if (NULL != eq->eq_queue && eq->eq_queue->ec_when <= now) {
be9751
+        retptr = eq->eq_queue;
be9751
+        eq->eq_queue = retptr->ec_next;
be9751
+    }
be9751
+    PR_Unlock(eq->eq_lock);
be9751
+    return retptr;
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * Call all events which are due to run.
be9751
+ * Note that if we've missed a schedule
be9751
+ * opportunity, we don't try to catch up
be9751
+ * by calling the function repeatedly.
be9751
+ */
be9751
+static void
be9751
+eq_call_all(void)
be9751
+{
be9751
+    slapi_eq_context *p;
be9751
+    time_t curtime = slapi_current_utc_time();
be9751
+
be9751
+    while ((p = eq_dequeue(curtime)) != NULL) {
be9751
+        /* Call the scheduled function */
be9751
+        p->ec_fn(p->ec_when, p->ec_arg);
be9751
+        slapi_log_err(SLAPI_LOG_HOUSE, NULL,
be9751
+                      "Event id %p called at %ld (scheduled for %ld)\n",
be9751
+                      p->ec_id, curtime, p->ec_when);
be9751
+        if (0UL != p->ec_interval) {
be9751
+            /* This is a repeating event. Requeue it. */
be9751
+            do {
be9751
+                p->ec_when += p->ec_interval;
be9751
+            } while (p->ec_when < curtime);
be9751
+            eq_enqueue(p);
be9751
+        } else {
be9751
+            slapi_ch_free((void **)&p);
be9751
+        }
be9751
+    }
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * The main event queue loop.
be9751
+ */
be9751
+static void
be9751
+eq_loop(void *arg __attribute__((unused)))
be9751
+{
be9751
+    while (eq_running) {
be9751
+        time_t curtime = slapi_current_utc_time();
be9751
+        PRIntervalTime timeout;
be9751
+        int until;
be9751
+        PR_Lock(eq->eq_lock);
be9751
+        while (!((NULL != eq->eq_queue) && (eq->eq_queue->ec_when <= curtime))) {
be9751
+            if (!eq_running) {
be9751
+                PR_Unlock(eq->eq_lock);
be9751
+                goto bye;
be9751
+            }
be9751
+            /* Compute new timeout */
be9751
+            if (NULL != eq->eq_queue) {
be9751
+                until = eq->eq_queue->ec_when - curtime;
be9751
+                timeout = PR_SecondsToInterval(until);
be9751
+            } else {
be9751
+                timeout = PR_INTERVAL_NO_TIMEOUT;
be9751
+            }
be9751
+            PR_WaitCondVar(eq->eq_cv, timeout);
be9751
+            curtime = slapi_current_utc_time();
be9751
+        }
be9751
+        /* There is some work to do */
be9751
+        PR_Unlock(eq->eq_lock);
be9751
+        eq_call_all();
be9751
+    }
be9751
+bye:
be9751
+    eq_stopped = 1;
be9751
+    PR_Lock(ss_lock);
be9751
+    PR_NotifyAllCondVar(ss_cv);
be9751
+    PR_Unlock(ss_lock);
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * Allocate and initialize the event queue structures.
be9751
+ */
be9751
+static PRStatus
be9751
+eq_create(void)
be9751
+{
be9751
+    PR_ASSERT(NULL == eq->eq_lock);
be9751
+    if ((eq->eq_lock = PR_NewLock()) == NULL) {
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_create", "PR_NewLock failed\n");
be9751
+        exit(1);
be9751
+    }
be9751
+    if ((eq->eq_cv = PR_NewCondVar(eq->eq_lock)) == NULL) {
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_create", "PR_NewCondVar failed\n");
be9751
+        exit(1);
be9751
+    }
be9751
+    if ((ss_lock = PR_NewLock()) == NULL) {
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_create", "PR_NewLock failed\n");
be9751
+        exit(1);
be9751
+    }
be9751
+    if ((ss_cv = PR_NewCondVar(ss_lock)) == NULL) {
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_create", "PR_NewCondVar failed\n");
be9751
+        exit(1);
be9751
+    }
be9751
+    eq->eq_queue = NULL;
be9751
+    eq_initialized = 1;
be9751
+    return PR_SUCCESS;
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * eq_start: start the event queue system.
be9751
+ *
be9751
+ * This should be called exactly once. It will start a
be9751
+ * thread which wakes up periodically and schedules events.
be9751
+ */
be9751
+void
be9751
+eq_start()
be9751
+{
be9751
+    PR_ASSERT(eq_initialized);
be9751
+    eq_running = 1;
be9751
+    if ((eq_loop_tid = PR_CreateThread(PR_USER_THREAD, (VFP)eq_loop,
be9751
+                                       NULL, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD,
be9751
+                                       SLAPD_DEFAULT_THREAD_STACKSIZE)) == NULL) {
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_start", "eq_loop PR_CreateThread failed\n");
be9751
+        exit(1);
be9751
+    }
be9751
+    slapi_log_err(SLAPI_LOG_HOUSE, NULL, "event queue services have started\n");
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * eq_init: initialize the event queue system.
be9751
+ *
be9751
+ * This function should be called early in server startup.
be9751
+ * Once it has been called, the event queue will queue
be9751
+ * events, but will not fire any events. Once all of the
be9751
+ * server plugins have been started, the eq_start()
be9751
+ * function should be called, and events will then start
be9751
+ * to fire.
be9751
+ */
be9751
+void
be9751
+eq_init()
be9751
+{
be9751
+    if (!eq_initialized) {
be9751
+        if (PR_SUCCESS != PR_CallOnce(&init_once, eq_create)) {
be9751
+            slapi_log_err(SLAPI_LOG_ERR, "eq_init", "eq_create failed\n");
be9751
+        }
be9751
+    }
be9751
+}
be9751
+
be9751
+
be9751
+/*
be9751
+ * eq_stop: shut down the event queue system.
be9751
+ * Does not return until event queue is fully
be9751
+ * shut down.
be9751
+ */
be9751
+void
be9751
+eq_stop()
be9751
+{
be9751
+    slapi_eq_context *p, *q;
be9751
+
be9751
+    if (NULL == eq || NULL == eq->eq_lock) { /* never started */
be9751
+        eq_stopped = 1;
be9751
+        return;
be9751
+    }
be9751
+
be9751
+    eq_stopped = 0;
be9751
+    eq_running = 0;
be9751
+    /*
be9751
+     * Signal the eq thread function to stop, and wait until
be9751
+     * it acknowledges by setting eq_stopped.
be9751
+     */
be9751
+    while (!eq_stopped) {
be9751
+        PR_Lock(eq->eq_lock);
be9751
+        PR_NotifyAllCondVar(eq->eq_cv);
be9751
+        PR_Unlock(eq->eq_lock);
be9751
+        PR_Lock(ss_lock);
be9751
+        PR_WaitCondVar(ss_cv, PR_MillisecondsToInterval(100));
be9751
+        PR_Unlock(ss_lock);
be9751
+    }
be9751
+    (void)PR_JoinThread(eq_loop_tid);
be9751
+    /*
be9751
+     * XXXggood we don't free the actual event queue data structures.
be9751
+     * This is intentional, to allow enqueueing/cancellation of events
be9751
+     * even after event queue services have shut down (these are no-ops).
be9751
+     * The downside is that the event queue can't be stopped and restarted
be9751
+     * easily.
be9751
+     */
be9751
+    PR_Lock(eq->eq_lock);
be9751
+    p = eq->eq_queue;
be9751
+    while (p != NULL) {
be9751
+        q = p->ec_next;
be9751
+        slapi_ch_free((void **)&p);
be9751
+        /* Some ec_arg could get leaked here in shutdown (e.g., replica_name)
be9751
+         * This can be fixed by specifying a flag when the context is queued.
be9751
+         * [After 6.2]
be9751
+         */
be9751
+        p = q;
be9751
+    }
be9751
+    PR_Unlock(eq->eq_lock);
be9751
+    slapi_log_err(SLAPI_LOG_HOUSE, NULL, "event queue services have shut down\n");
be9751
+}
be9751
+
be9751
+/*
be9751
+ * return arg (ec_arg) only if the context is in the event queue
be9751
+ */
be9751
+void *
be9751
+slapi_eq_get_arg(Slapi_Eq_Context ctx)
be9751
+{
be9751
+    slapi_eq_context **p;
be9751
+
be9751
+    PR_ASSERT(eq_initialized);
be9751
+    if (eq && !eq_stopped) {
be9751
+        PR_Lock(eq->eq_lock);
be9751
+        p = &(eq->eq_queue);
be9751
+        while (p && *p != NULL) {
be9751
+            if ((*p)->ec_id == ctx) {
be9751
+                PR_Unlock(eq->eq_lock);
be9751
+                return (*p)->ec_arg;
be9751
+            } else {
be9751
+                p = &((*p)->ec_next);
be9751
+            }
be9751
+        }
be9751
+        PR_Unlock(eq->eq_lock);
be9751
+    }
be9751
+    return NULL;
be9751
+}
be9751
diff --git a/ldap/servers/slapd/eventq.c b/ldap/servers/slapd/eventq.c
be9751
index e1900724f..4c39e08cf 100644
be9751
--- a/ldap/servers/slapd/eventq.c
be9751
+++ b/ldap/servers/slapd/eventq.c
be9751
@@ -17,14 +17,14 @@ eventq.c - Event queue/scheduling system.
be9751
 
be9751
 There are 3 publicly-accessible entry points:
be9751
 
be9751
-slapi_eq_once(): cause an event to happen exactly once
be9751
-slapi_eq_repeat(): cause an event to happen repeatedly
be9751
-slapi_eq_cancel(): cancel a pending event
be9751
+slapi_eq_once_rel(): cause an event to happen exactly once
be9751
+slapi_eq_repeat_rel(): cause an event to happen repeatedly
be9751
+slapi_eq_cancel_rel(): cancel a pending event
be9751
 
be9751
 There is also an initialization point which must be
be9751
 called by the server to initialize the event queue system:
be9751
-eq_start(), and an entry point used to shut down the system:
be9751
-eq_stop().
be9751
+eq_start_rel(), and an entry point used to shut down the system:
be9751
+eq_stop_rel().
be9751
 *********************************************************** */
be9751
 
be9751
 #include "slap.h"
be9751
@@ -60,36 +60,36 @@ typedef struct _event_queue
be9751
 /*
be9751
  * The event queue itself.
be9751
  */
be9751
-static event_queue eqs = {0};
be9751
-static event_queue *eq = &eqs;
be9751
+static event_queue eqs_rel = {0};
be9751
+static event_queue *eq_rel = &eqs_rel;
be9751
 
be9751
 /*
be9751
  * Thread ID of the main thread loop
be9751
  */
be9751
-static PRThread *eq_loop_tid = NULL;
be9751
+static PRThread *eq_loop_rel_tid = NULL;
be9751
 
be9751
 /*
be9751
  * Flags used to control startup/shutdown of the event queue
be9751
  */
be9751
-static int eq_running = 0;
be9751
-static int eq_stopped = 0;
be9751
-static int eq_initialized = 0;
be9751
-static pthread_mutex_t ss_lock;
be9751
-static pthread_cond_t ss_cv;
be9751
-PRCallOnceType init_once = {0};
be9751
+static int eq_rel_running = 0;
be9751
+static int eq_rel_stopped = 0;
be9751
+static int eq_rel_initialized = 0;
be9751
+static pthread_mutex_t ss_rel_lock;
be9751
+static pthread_cond_t ss_rel_cv;
be9751
+PRCallOnceType init_once_rel = {0};
be9751
 
be9751
 /* Forward declarations */
be9751
-static slapi_eq_context *eq_new(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval);
be9751
-static void eq_enqueue(slapi_eq_context *newec);
be9751
-static slapi_eq_context *eq_dequeue(time_t now);
be9751
-static PRStatus eq_create(void);
be9751
+static slapi_eq_context *eq_new_rel(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval);
be9751
+static void eq_enqueue_rel(slapi_eq_context *newec);
be9751
+static slapi_eq_context *eq_dequeue_rel(time_t now);
be9751
+static PRStatus eq_create_rel(void);
be9751
 
be9751
 
be9751
 /* ******************************************************** */
be9751
 
be9751
 
be9751
 /*
be9751
- * slapi_eq_once: cause an event to happen exactly once.
be9751
+ * slapi_eq_once_rel: cause an event to happen exactly once.
be9751
  *
be9751
  * Arguments:
be9751
  *  fn: the function to call
be9751
@@ -101,18 +101,18 @@ static PRStatus eq_create(void);
be9751
  *  event.
be9751
  */
be9751
 Slapi_Eq_Context
be9751
-slapi_eq_once(slapi_eq_fn_t fn, void *arg, time_t when)
be9751
+slapi_eq_once_rel(slapi_eq_fn_t fn, void *arg, time_t when)
be9751
 {
be9751
     slapi_eq_context *tmp;
be9751
-    PR_ASSERT(eq_initialized);
be9751
-    if (!eq_stopped) {
be9751
+    PR_ASSERT(eq_rel_initialized);
be9751
+    if (!eq_rel_stopped) {
be9751
 
be9751
         Slapi_Eq_Context id;
be9751
 
be9751
-        tmp = eq_new(fn, arg, when, 0UL);
be9751
+        tmp = eq_new_rel(fn, arg, when, 0UL);
be9751
         id = tmp->ec_id;
be9751
 
be9751
-        eq_enqueue(tmp);
be9751
+        eq_enqueue_rel(tmp);
be9751
 
be9751
         /* After this point, <tmp> may have      */
be9751
         /* been freed, depending on the thread   */
be9751
@@ -128,7 +128,7 @@ slapi_eq_once(slapi_eq_fn_t fn, void *arg, time_t when)
be9751
 
be9751
 
be9751
 /*
be9751
- * slapi_eq_repeat: cause an event to happen repeatedly.
be9751
+ * slapi_eq_repeat_rel: cause an event to happen repeatedly.
be9751
  *
be9751
  * Arguments:
be9751
  *  fn: the function to call
be9751
@@ -141,13 +141,13 @@ slapi_eq_once(slapi_eq_fn_t fn, void *arg, time_t when)
be9751
  *  the caller can use to refer to this particular scheduled
be9751
  */
be9751
 Slapi_Eq_Context
be9751
-slapi_eq_repeat(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval)
be9751
+slapi_eq_repeat_rel(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval)
be9751
 {
be9751
     slapi_eq_context *tmp;
be9751
-    PR_ASSERT(eq_initialized);
be9751
-    if (!eq_stopped) {
be9751
-        tmp = eq_new(fn, arg, when, interval);
be9751
-        eq_enqueue(tmp);
be9751
+    PR_ASSERT(eq_rel_initialized);
be9751
+    if (!eq_rel_stopped) {
be9751
+        tmp = eq_new_rel(fn, arg, when, interval);
be9751
+        eq_enqueue_rel(tmp);
be9751
         slapi_log_err(SLAPI_LOG_HOUSE, NULL,
be9751
                       "added repeating event id %p at time %ld, interval %lu\n",
be9751
                       tmp->ec_id, when, interval);
be9751
@@ -158,20 +158,20 @@ slapi_eq_repeat(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval
be9751
 
be9751
 
be9751
 /*
be9751
- * slapi_eq_cancel: cancel a pending event.
be9751
+ * slapi_eq_cancel_rel: cancel a pending event.
be9751
  * Arguments:
be9751
  *  ctx: the context of the event which should be de-scheduled
be9751
  */
be9751
 int
be9751
-slapi_eq_cancel(Slapi_Eq_Context ctx)
be9751
+slapi_eq_cancel_rel(Slapi_Eq_Context ctx)
be9751
 {
be9751
     slapi_eq_context **p, *tmp = NULL;
be9751
     int found = 0;
be9751
 
be9751
-    PR_ASSERT(eq_initialized);
be9751
-    if (!eq_stopped) {
be9751
-        pthread_mutex_lock(&(eq->eq_lock));
be9751
-        p = &(eq->eq_queue);
be9751
+    PR_ASSERT(eq_rel_initialized);
be9751
+    if (!eq_rel_stopped) {
be9751
+        pthread_mutex_lock(&(eq_rel->eq_lock));
be9751
+        p = &(eq_rel->eq_queue);
be9751
         while (!found && *p != NULL) {
be9751
             if ((*p)->ec_id == ctx) {
be9751
                 tmp = *p;
be9751
@@ -182,7 +182,7 @@ slapi_eq_cancel(Slapi_Eq_Context ctx)
be9751
                 p = &((*p)->ec_next);
be9751
             }
be9751
         }
be9751
-        pthread_mutex_unlock(&(eq->eq_lock));
be9751
+        pthread_mutex_unlock(&(eq_rel->eq_lock));
be9751
     }
be9751
     slapi_log_err(SLAPI_LOG_HOUSE, NULL,
be9751
                   "cancellation of event id %p requested: %s\n",
be9751
@@ -195,7 +195,7 @@ slapi_eq_cancel(Slapi_Eq_Context ctx)
be9751
  * Construct a new ec structure
be9751
  */
be9751
 static slapi_eq_context *
be9751
-eq_new(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval)
be9751
+eq_new_rel(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval)
be9751
 {
be9751
     slapi_eq_context *retptr = (slapi_eq_context *)slapi_ch_calloc(1, sizeof(slapi_eq_context));
be9751
 
be9751
@@ -218,14 +218,14 @@ eq_new(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval)
be9751
  * Add a new event to the event queue.
be9751
  */
be9751
 static void
be9751
-eq_enqueue(slapi_eq_context *newec)
be9751
+eq_enqueue_rel(slapi_eq_context *newec)
be9751
 {
be9751
     slapi_eq_context **p;
be9751
 
be9751
     PR_ASSERT(NULL != newec);
be9751
-    pthread_mutex_lock(&(eq->eq_lock));
be9751
+    pthread_mutex_lock(&(eq_rel->eq_lock));
be9751
     /* Insert <newec> in order (sorted by start time) in the list */
be9751
-    for (p = &(eq->eq_queue); *p != NULL; p = &((*p)->ec_next)) {
be9751
+    for (p = &(eq_rel->eq_queue); *p != NULL; p = &((*p)->ec_next)) {
be9751
         if ((*p)->ec_when > newec->ec_when) {
be9751
             break;
be9751
         }
be9751
@@ -236,8 +236,8 @@ eq_enqueue(slapi_eq_context *newec)
be9751
         newec->ec_next = NULL;
be9751
     }
be9751
     *p = newec;
be9751
-    pthread_cond_signal(&(eq->eq_cv)); /* wake up scheduler thread */
be9751
-    pthread_mutex_unlock(&(eq->eq_lock));
be9751
+    pthread_cond_signal(&(eq_rel->eq_cv)); /* wake up scheduler thread */
be9751
+    pthread_mutex_unlock(&(eq_rel->eq_lock));
be9751
 }
be9751
 
be9751
 
be9751
@@ -247,16 +247,16 @@ eq_enqueue(slapi_eq_context *newec)
be9751
  * to it. Otherwise, return NULL.
be9751
  */
be9751
 static slapi_eq_context *
be9751
-eq_dequeue(time_t now)
be9751
+eq_dequeue_rel(time_t now)
be9751
 {
be9751
     slapi_eq_context *retptr = NULL;
be9751
 
be9751
-    pthread_mutex_lock(&(eq->eq_lock));
be9751
-    if (NULL != eq->eq_queue && eq->eq_queue->ec_when <= now) {
be9751
-        retptr = eq->eq_queue;
be9751
-        eq->eq_queue = retptr->ec_next;
be9751
+    pthread_mutex_lock(&(eq_rel->eq_lock));
be9751
+    if (NULL != eq_rel->eq_queue && eq_rel->eq_queue->ec_when <= now) {
be9751
+        retptr = eq_rel->eq_queue;
be9751
+        eq_rel->eq_queue = retptr->ec_next;
be9751
     }
be9751
-    pthread_mutex_unlock(&(eq->eq_lock));
be9751
+    pthread_mutex_unlock(&(eq_rel->eq_lock));
be9751
     return retptr;
be9751
 }
be9751
 
be9751
@@ -268,12 +268,12 @@ eq_dequeue(time_t now)
be9751
  * by calling the function repeatedly.
be9751
  */
be9751
 static void
be9751
-eq_call_all(void)
be9751
+eq_call_all_rel(void)
be9751
 {
be9751
     slapi_eq_context *p;
be9751
     time_t curtime = slapi_current_rel_time_t();
be9751
 
be9751
-    while ((p = eq_dequeue(curtime)) != NULL) {
be9751
+    while ((p = eq_dequeue_rel(curtime)) != NULL) {
be9751
         /* Call the scheduled function */
be9751
         p->ec_fn(p->ec_when, p->ec_arg);
be9751
         slapi_log_err(SLAPI_LOG_HOUSE, NULL,
be9751
@@ -284,7 +284,7 @@ eq_call_all(void)
be9751
             do {
be9751
                 p->ec_when += p->ec_interval;
be9751
             } while (p->ec_when < curtime);
be9751
-            eq_enqueue(p);
be9751
+            eq_enqueue_rel(p);
be9751
         } else {
be9751
             slapi_ch_free((void **)&p);
be9751
         }
be9751
@@ -296,38 +296,38 @@ eq_call_all(void)
be9751
  * The main event queue loop.
be9751
  */
be9751
 static void
be9751
-eq_loop(void *arg __attribute__((unused)))
be9751
+eq_loop_rel(void *arg __attribute__((unused)))
be9751
 {
be9751
-    while (eq_running) {
be9751
+    while (eq_rel_running) {
be9751
         time_t curtime = slapi_current_rel_time_t();
be9751
         int until;
be9751
 
be9751
-        pthread_mutex_lock(&(eq->eq_lock));
be9751
-        while (!((NULL != eq->eq_queue) && (eq->eq_queue->ec_when <= curtime))) {
be9751
-            if (!eq_running) {
be9751
-                pthread_mutex_unlock(&(eq->eq_lock));
be9751
+        pthread_mutex_lock(&(eq_rel->eq_lock));
be9751
+        while (!((NULL != eq_rel->eq_queue) && (eq_rel->eq_queue->ec_when <= curtime))) {
be9751
+            if (!eq_rel_running) {
be9751
+                pthread_mutex_unlock(&(eq_rel->eq_lock));
be9751
                 goto bye;
be9751
             }
be9751
             /* Compute new timeout */
be9751
-            if (NULL != eq->eq_queue) {
be9751
+            if (NULL != eq_rel->eq_queue) {
be9751
                 struct timespec current_time = slapi_current_rel_time_hr();
be9751
-                until = eq->eq_queue->ec_when - curtime;
be9751
+                until = eq_rel->eq_queue->ec_when - curtime;
be9751
                 current_time.tv_sec += until;
be9751
-                pthread_cond_timedwait(&eq->eq_cv, &eq->eq_lock, &current_time);
be9751
+                pthread_cond_timedwait(&eq_rel->eq_cv, &eq_rel->eq_lock, &current_time);
be9751
             } else {
be9751
-                pthread_cond_wait(&eq->eq_cv, &eq->eq_lock);
be9751
+                pthread_cond_wait(&eq_rel->eq_cv, &eq_rel->eq_lock);
be9751
             }
be9751
             curtime = slapi_current_rel_time_t();
be9751
         }
be9751
         /* There is some work to do */
be9751
-        pthread_mutex_unlock(&(eq->eq_lock));
be9751
-        eq_call_all();
be9751
+        pthread_mutex_unlock(&(eq_rel->eq_lock));
be9751
+        eq_call_all_rel();
be9751
     }
be9751
 bye:
be9751
-    eq_stopped = 1;
be9751
-    pthread_mutex_lock(&ss_lock);
be9751
-    pthread_cond_broadcast(&ss_cv);
be9751
-    pthread_mutex_unlock(&ss_lock);
be9751
+    eq_rel_stopped = 1;
be9751
+    pthread_mutex_lock(&ss_rel_lock);
be9751
+    pthread_cond_broadcast(&ss_rel_cv);
be9751
+    pthread_mutex_unlock(&ss_rel_lock);
be9751
 }
be9751
 
be9751
 
be9751
@@ -335,73 +335,73 @@ bye:
be9751
  * Allocate and initialize the event queue structures.
be9751
  */
be9751
 static PRStatus
be9751
-eq_create(void)
be9751
+eq_create_rel(void)
be9751
 {
be9751
     pthread_condattr_t condAttr;
be9751
     int rc = 0;
be9751
 
be9751
     /* Init the eventq mutex and cond var */
be9751
-    if (pthread_mutex_init(&eq->eq_lock, NULL) != 0) {
be9751
-        slapi_log_err(SLAPI_LOG_ERR, "eq_create",
be9751
+    if (pthread_mutex_init(&eq_rel->eq_lock, NULL) != 0) {
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_create_rel",
be9751
                       "Failed to create lock: error %d (%s)\n",
be9751
                       rc, strerror(rc));
be9751
         exit(1);
be9751
     }
be9751
     if ((rc = pthread_condattr_init(&condAttr)) != 0) {
be9751
-        slapi_log_err(SLAPI_LOG_ERR, "eq_create",
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_create_rel",
be9751
                       "Failed to create new condition attribute variable. error %d (%s)\n",
be9751
                       rc, strerror(rc));
be9751
         exit(1);
be9751
     }
be9751
     if ((rc = pthread_condattr_setclock(&condAttr, CLOCK_MONOTONIC)) != 0) {
be9751
-        slapi_log_err(SLAPI_LOG_ERR, "eq_create",
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_create_rel",
be9751
                       "Cannot set condition attr clock. error %d (%s)\n",
be9751
                       rc, strerror(rc));
be9751
         exit(1);
be9751
     }
be9751
-    if ((rc = pthread_cond_init(&eq->eq_cv, &condAttr)) != 0) {
be9751
-        slapi_log_err(SLAPI_LOG_ERR, "eq_create",
be9751
+    if ((rc = pthread_cond_init(&eq_rel->eq_cv, &condAttr)) != 0) {
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_create_rel",
be9751
                       "Failed to create new condition variable. error %d (%s)\n",
be9751
                       rc, strerror(rc));
be9751
         exit(1);
be9751
     }
be9751
 
be9751
     /* Init the "ss" mutex and condition var */
be9751
-    if (pthread_mutex_init(&ss_lock, NULL) != 0) {
be9751
-        slapi_log_err(SLAPI_LOG_ERR, "eq_create",
be9751
+    if (pthread_mutex_init(&ss_rel_lock, NULL) != 0) {
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_create_rel",
be9751
                       "Failed to create ss lock: error %d (%s)\n",
be9751
                       rc, strerror(rc));
be9751
         exit(1);
be9751
     }
be9751
-    if ((rc = pthread_cond_init(&ss_cv, &condAttr)) != 0) {
be9751
-        slapi_log_err(SLAPI_LOG_ERR, "eq_create",
be9751
+    if ((rc = pthread_cond_init(&ss_rel_cv, &condAttr)) != 0) {
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_create_rel",
be9751
                       "Failed to create new ss condition variable. error %d (%s)\n",
be9751
                       rc, strerror(rc));
be9751
         exit(1);
be9751
     }
be9751
     pthread_condattr_destroy(&condAttr); /* no longer needed */
be9751
 
be9751
-    eq->eq_queue = NULL;
be9751
-    eq_initialized = 1;
be9751
+    eq_rel->eq_queue = NULL;
be9751
+    eq_rel_initialized = 1;
be9751
     return PR_SUCCESS;
be9751
 }
be9751
 
be9751
 
be9751
 /*
be9751
- * eq_start: start the event queue system.
be9751
+ * eq_start_rel: start the event queue system.
be9751
  *
be9751
  * This should be called exactly once. It will start a
be9751
  * thread which wakes up periodically and schedules events.
be9751
  */
be9751
 void
be9751
-eq_start()
be9751
+eq_start_rel()
be9751
 {
be9751
-    PR_ASSERT(eq_initialized);
be9751
-    eq_running = 1;
be9751
-    if ((eq_loop_tid = PR_CreateThread(PR_USER_THREAD, (VFP)eq_loop,
be9751
+    PR_ASSERT(eq_rel_initialized);
be9751
+    eq_rel_running = 1;
be9751
+    if ((eq_loop_rel_tid = PR_CreateThread(PR_USER_THREAD, (VFP)eq_loop_rel,
be9751
                                        NULL, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD,
be9751
                                        SLAPD_DEFAULT_THREAD_STACKSIZE)) == NULL) {
be9751
-        slapi_log_err(SLAPI_LOG_ERR, "eq_start", "eq_loop PR_CreateThread failed\n");
be9751
+        slapi_log_err(SLAPI_LOG_ERR, "eq_start_rel", "eq_loop_rel PR_CreateThread failed\n");
be9751
         exit(1);
be9751
     }
be9751
     slapi_log_err(SLAPI_LOG_HOUSE, NULL, "event queue services have started\n");
be9751
@@ -409,55 +409,55 @@ eq_start()
be9751
 
be9751
 
be9751
 /*
be9751
- * eq_init: initialize the event queue system.
be9751
+ * eq_init_rel: initialize the event queue system.
be9751
  *
be9751
  * This function should be called early in server startup.
be9751
  * Once it has been called, the event queue will queue
be9751
  * events, but will not fire any events. Once all of the
be9751
- * server plugins have been started, the eq_start()
be9751
+ * server plugins have been started, the eq_start_rel()
be9751
  * function should be called, and events will then start
be9751
  * to fire.
be9751
  */
be9751
 void
be9751
-eq_init()
be9751
+eq_init_rel()
be9751
 {
be9751
-    if (!eq_initialized) {
be9751
-        if (PR_SUCCESS != PR_CallOnce(&init_once, eq_create)) {
be9751
-            slapi_log_err(SLAPI_LOG_ERR, "eq_init", "eq_create failed\n");
be9751
+    if (!eq_rel_initialized) {
be9751
+        if (PR_SUCCESS != PR_CallOnce(&init_once_rel, eq_create_rel)) {
be9751
+            slapi_log_err(SLAPI_LOG_ERR, "eq_init_rel", "eq_create_rel failed\n");
be9751
         }
be9751
     }
be9751
 }
be9751
 
be9751
 
be9751
 /*
be9751
- * eq_stop: shut down the event queue system.
be9751
+ * eq_stop_rel: shut down the event queue system.
be9751
  * Does not return until event queue is fully
be9751
  * shut down.
be9751
  */
be9751
 void
be9751
-eq_stop()
be9751
+eq_stop_rel()
be9751
 {
be9751
     slapi_eq_context *p, *q;
be9751
 
be9751
-    if (NULL == eq) { /* never started */
be9751
-        eq_stopped = 1;
be9751
+    if (NULL == eq_rel) { /* never started */
be9751
+        eq_rel_stopped = 1;
be9751
         return;
be9751
     }
be9751
 
be9751
-    eq_stopped = 0;
be9751
-    eq_running = 0;
be9751
+    eq_rel_stopped = 0;
be9751
+    eq_rel_running = 0;
be9751
     /*
be9751
      * Signal the eq thread function to stop, and wait until
be9751
-     * it acknowledges by setting eq_stopped.
be9751
+     * it acknowledges by setting eq_rel_stopped.
be9751
      */
be9751
-    while (!eq_stopped) {
be9751
+    while (!eq_rel_stopped) {
be9751
         struct timespec current_time = {0};
be9751
 
be9751
-        pthread_mutex_lock(&(eq->eq_lock));
be9751
-        pthread_cond_broadcast(&(eq->eq_cv));
be9751
-        pthread_mutex_unlock(&(eq->eq_lock));
be9751
+        pthread_mutex_lock(&(eq_rel->eq_lock));
be9751
+        pthread_cond_broadcast(&(eq_rel->eq_cv));
be9751
+        pthread_mutex_unlock(&(eq_rel->eq_lock));
be9751
 
be9751
-        pthread_mutex_lock(&ss_lock);
be9751
+        pthread_mutex_lock(&ss_rel_lock);
be9751
         clock_gettime(CLOCK_MONOTONIC, &current_time);
be9751
         if (current_time.tv_nsec + 100000000 > 1000000000) {
be9751
             /* nanoseconds will overflow, adjust the seconds and nanoseconds */
be9751
@@ -467,10 +467,10 @@ eq_stop()
be9751
         } else {
be9751
             current_time.tv_nsec += 100000000; /* 100 ms */
be9751
         }
be9751
-        pthread_cond_timedwait(&ss_cv, &ss_lock, &current_time);
be9751
-        pthread_mutex_unlock(&ss_lock);
be9751
+        pthread_cond_timedwait(&ss_rel_cv, &ss_rel_lock, &current_time);
be9751
+        pthread_mutex_unlock(&ss_rel_lock);
be9751
     }
be9751
-    (void)PR_JoinThread(eq_loop_tid);
be9751
+    (void)PR_JoinThread(eq_loop_rel_tid);
be9751
     /*
be9751
      * XXXggood we don't free the actual event queue data structures.
be9751
      * This is intentional, to allow enqueueing/cancellation of events
be9751
@@ -478,8 +478,8 @@ eq_stop()
be9751
      * The downside is that the event queue can't be stopped and restarted
be9751
      * easily.
be9751
      */
be9751
-    pthread_mutex_lock(&(eq->eq_lock));
be9751
-    p = eq->eq_queue;
be9751
+    pthread_mutex_lock(&(eq_rel->eq_lock));
be9751
+    p = eq_rel->eq_queue;
be9751
     while (p != NULL) {
be9751
         q = p->ec_next;
be9751
         slapi_ch_free((void **)&p);
be9751
@@ -489,7 +489,7 @@ eq_stop()
be9751
          */
be9751
         p = q;
be9751
     }
be9751
-    pthread_mutex_unlock(&(eq->eq_lock));
be9751
+    pthread_mutex_unlock(&(eq_rel->eq_lock));
be9751
     slapi_log_err(SLAPI_LOG_HOUSE, NULL, "event queue services have shut down\n");
be9751
 }
be9751
 
be9751
@@ -497,23 +497,23 @@ eq_stop()
be9751
  * return arg (ec_arg) only if the context is in the event queue
be9751
  */
be9751
 void *
be9751
-slapi_eq_get_arg(Slapi_Eq_Context ctx)
be9751
+slapi_eq_get_arg_rel(Slapi_Eq_Context ctx)
be9751
 {
be9751
     slapi_eq_context **p;
be9751
 
be9751
-    PR_ASSERT(eq_initialized);
be9751
-    if (eq && !eq_stopped) {
be9751
-        pthread_mutex_lock(&(eq->eq_lock));
be9751
-        p = &(eq->eq_queue);
be9751
+    PR_ASSERT(eq_rel_initialized);
be9751
+    if (eq_rel && !eq_rel_stopped) {
be9751
+        pthread_mutex_lock(&(eq_rel->eq_lock));
be9751
+        p = &(eq_rel->eq_queue);
be9751
         while (p && *p != NULL) {
be9751
             if ((*p)->ec_id == ctx) {
be9751
-                pthread_mutex_unlock(&(eq->eq_lock));
be9751
+                pthread_mutex_unlock(&(eq_rel->eq_lock));
be9751
                 return (*p)->ec_arg;
be9751
             } else {
be9751
                 p = &((*p)->ec_next);
be9751
             }
be9751
         }
be9751
-        pthread_mutex_unlock(&(eq->eq_lock));
be9751
+        pthread_mutex_unlock(&(eq_rel->eq_lock));
be9751
     }
be9751
     return NULL;
be9751
 }
be9751
diff --git a/ldap/servers/slapd/main.c b/ldap/servers/slapd/main.c
be9751
index 104f6826c..dbc8cec15 100644
be9751
--- a/ldap/servers/slapd/main.c
be9751
+++ b/ldap/servers/slapd/main.c
be9751
@@ -979,7 +979,8 @@ main(int argc, char **argv)
be9751
         fedse_create_startOK(DSE_FILENAME, DSE_STARTOKFILE,
be9751
                              slapdFrontendConfig->configdir);
be9751
 
be9751
-        eq_init(); /* must be done before plugins started */
be9751
+        eq_init(); /* DEPRECATED */
be9751
+        eq_init_rel(); /* must be done before plugins started */
be9751
 
be9751
         /* Start the SNMP collator if counters are enabled. */
be9751
         if (config_get_slapi_counters()) {
be9751
@@ -1035,7 +1036,8 @@ main(int argc, char **argv)
be9751
             goto cleanup;
be9751
         }
be9751
 
be9751
-        eq_start(); /* must be done after plugins started */
be9751
+        eq_start(); /* must be done after plugins started - DEPRECATED */
be9751
+        eq_start_rel(); /* must be done after plugins started */
be9751
 
be9751
 #ifdef HPUX10
be9751
         /* HPUX linker voodoo */
be9751
@@ -2205,10 +2207,13 @@ slapd_exemode_db2ldif(int argc, char **argv, struct main_config *mcfg)
be9751
              */
be9751
             plugin_get_plugin_dependencies(repl_plg_name, &plugin_list);
be9751
 
be9751
-            eq_init();                /* must be done before plugins started */
be9751
+            eq_init(); /* must be done before plugins started - DEPRECATED */
be9751
+            eq_init_rel(); /* must be done before plugins started */
be9751
+
be9751
             ps_init_psearch_system(); /* must come before plugin_startall() */
be9751
             plugin_startall(argc, argv, plugin_list);
be9751
-            eq_start(); /* must be done after plugins started */
be9751
+            eq_start(); /* must be done after plugins started - DEPRECATED*/
be9751
+            eq_start_rel(); /* must be done after plugins started */
be9751
             charray_free(plugin_list);
be9751
         }
be9751
 
be9751
@@ -2263,8 +2268,9 @@ slapd_exemode_db2ldif(int argc, char **argv, struct main_config *mcfg)
be9751
     charray_free(mcfg->cmd_line_instance_names);
be9751
     charray_free(mcfg->db2ldif_include);
be9751
     if (mcfg->db2ldif_dump_replica) {
be9751
-        eq_stop(); /* event queue should be shutdown before closing
be9751
-                              all plugins (especailly, replication plugin) */
be9751
+        eq_stop(); /* DEPRECATED*/
be9751
+        eq_stop_rel(); /* event queue should be shutdown before closing
be9751
+                          all plugins (especially, replication plugin) */
be9751
         plugin_closeall(1 /* Close Backends */, 1 /* Close Globals */);
be9751
     }
be9751
     return (return_value);
be9751
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
be9751
index 3acc24f03..87080dd82 100644
be9751
--- a/ldap/servers/slapd/proto-slap.h
be9751
+++ b/ldap/servers/slapd/proto-slap.h
be9751
@@ -1322,7 +1322,6 @@ void factory_destroy_extension(int type, void *object, void *parent, void **exte
be9751
 /*
be9751
  * auditlog.c
be9751
  */
be9751
-
be9751
 void write_audit_log_entry(Slapi_PBlock *pb);
be9751
 void auditlog_hide_unhashed_pw(void);
be9751
 void auditlog_expose_unhashed_pw(void);
be9751
@@ -1334,10 +1333,15 @@ void auditfaillog_expose_unhashed_pw(void);
be9751
 /*
be9751
  * eventq.c
be9751
  */
be9751
+void eq_init_rel(void);
be9751
+void eq_start_rel(void);
be9751
+void eq_stop_rel(void);
be9751
+/* Deprecated eventq that uses REALTIME clock instead of MONOTONIC */
be9751
 void eq_init(void);
be9751
 void eq_start(void);
be9751
 void eq_stop(void);
be9751
 
be9751
+
be9751
 /*
be9751
  * uniqueidgen.c
be9751
  */
be9751
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
be9751
index 55ded5eb8..f76b86e3c 100644
be9751
--- a/ldap/servers/slapd/slapi-plugin.h
be9751
+++ b/ldap/servers/slapd/slapi-plugin.h
be9751
@@ -6084,7 +6084,7 @@ void slapi_lock_mutex(Slapi_Mutex *mutex);
be9751
 int slapi_unlock_mutex(Slapi_Mutex *mutex);
be9751
 Slapi_CondVar *slapi_new_condvar(Slapi_Mutex *mutex);
be9751
 void slapi_destroy_condvar(Slapi_CondVar *cvar);
be9751
-int slapi_wait_condvar(Slapi_CondVar *cvar, struct timeval *timeout);
be9751
+int slapi_wait_condvar(Slapi_CondVar *cvar, struct timeval *timeout) __attribute__((deprecated));
be9751
 int slapi_notify_condvar(Slapi_CondVar *cvar, int notify_all);
be9751
 int slapi_wait_condvar_pt(Slapi_CondVar *cvar, Slapi_Mutex *mutex, struct timeval *timeout);
be9751
 
be9751
@@ -8059,24 +8059,24 @@ typedef void (*slapi_eq_fn_t)(time_t when, void *arg);
be9751
  *
be9751
  * \param fn The function to call when the event is triggered.
be9751
  * \param arg An argument to pass to the called function.
be9751
- * \param when The time that the function should be called.
be9751
+ * \param when The time that the function should be called(MONOTONIC clock).
be9751
  *
be9751
  * \return slapi_eq_context
be9751
  */
be9751
-Slapi_Eq_Context slapi_eq_once(slapi_eq_fn_t fn, void *arg, time_t when);
be9751
+Slapi_Eq_Context slapi_eq_once_rel(slapi_eq_fn_t fn, void *arg, time_t when);
be9751
 
be9751
 /**
be9751
  * Cause an event to happen repeatedly.
be9751
  *
be9751
  * \param fn The function to call when the vent is triggered.
be9751
  * \param arg An argument to pass to the called function.
be9751
- * \param when The time that the function should be called.
be9751
+ * \param when The time that the function should be called(MONOTONIC clock).
be9751
  * \param interval The amount of time (in milliseconds) between
be9751
  *                 successive calls to the function.
be9751
  *
be9751
  * \return slapi_eq_context
be9751
  */
be9751
-Slapi_Eq_Context slapi_eq_repeat(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval);
be9751
+Slapi_Eq_Context slapi_eq_repeat_rel(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval);
be9751
 
be9751
 /**
be9751
  * Cause a scheduled event to be canceled.
be9751
@@ -8086,7 +8086,7 @@ Slapi_Eq_Context slapi_eq_repeat(slapi_eq_fn_t fn, void *arg, time_t when, unsig
be9751
  * \return 1 If event was found and canceled.
be9751
  * \return 0 If event was not found in the queue.
be9751
  */
be9751
-int slapi_eq_cancel(Slapi_Eq_Context ctx);
be9751
+int slapi_eq_cancel_rel(Slapi_Eq_Context ctx);
be9751
 
be9751
 /**
be9751
  * Return the event's argument.
be9751
@@ -8095,7 +8095,55 @@ int slapi_eq_cancel(Slapi_Eq_Context ctx);
be9751
  *
be9751
  * \return A pointer to the event argument.
be9751
  */
be9751
-void *slapi_eq_get_arg(Slapi_Eq_Context ctx);
be9751
+void *slapi_eq_get_arg_rel(Slapi_Eq_Context ctx);
be9751
+
be9751
+/*
be9751
+ * These event queue functions are now DEPRECATED as they REALTIME clocks
be9751
+ * instead of the preferred MONOTONIC clocks.
be9751
+ */
be9751
+
be9751
+/**
be9751
+ * Cause an event to happen exactly once.
be9751
+ *
be9751
+ * \param fn The function to call when the event is triggered.
be9751
+ * \param arg An argument to pass to the called function.
be9751
+ * \param when The time that the function should be called(REALTIME clock).
be9751
+ *
be9751
+ * \return slapi_eq_context
be9751
+ */
be9751
+Slapi_Eq_Context slapi_eq_once(slapi_eq_fn_t fn, void *arg, time_t when) __attribute__((deprecated));
be9751
+
be9751
+/**
be9751
+ * Cause an event to happen repeatedly.
be9751
+ *
be9751
+ * \param fn The function to call when the vent is triggered.
be9751
+ * \param arg An argument to pass to the called function.
be9751
+ * \param when The time that the function should be called(REALTIME clock).
be9751
+ * \param interval The amount of time (in milliseconds) between
be9751
+ *                 successive calls to the function.
be9751
+ *
be9751
+ * \return slapi_eq_context
be9751
+ */
be9751
+Slapi_Eq_Context slapi_eq_repeat(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval) __attribute__((deprecated));
be9751
+
be9751
+/**
be9751
+ * Cause a scheduled event to be canceled.
be9751
+ *
be9751
+ * \param ctx The event object to cancel
be9751
+ *
be9751
+ * \return 1 If event was found and canceled.
be9751
+ * \return 0 If event was not found in the queue.
be9751
+ */
be9751
+int slapi_eq_cancel(Slapi_Eq_Context ctx) __attribute__((deprecated));
be9751
+
be9751
+/**
be9751
+ * Return the event's argument.
be9751
+ *
be9751
+ * \param ctx The event object
be9751
+ *
be9751
+ * \return A pointer to the event argument.
be9751
+ */
be9751
+void *slapi_eq_get_arg(Slapi_Eq_Context ctx) __attribute__((deprecated));
be9751
 
be9751
 /**
be9751
  * Construct a full path and name of a plugin.
be9751
diff --git a/ldap/servers/slapd/slapi2runtime.c b/ldap/servers/slapd/slapi2runtime.c
be9751
index 85dc4c9a8..53927934a 100644
be9751
--- a/ldap/servers/slapd/slapi2runtime.c
be9751
+++ b/ldap/servers/slapd/slapi2runtime.c
be9751
@@ -133,7 +133,7 @@ slapi_destroy_condvar(Slapi_CondVar *cvar)
be9751
 
be9751
 
be9751
 /*
be9751
- * Function: slapi_wait_condvar
be9751
+ * Function: slapi_wait_condvar (DEPRECATED)
be9751
  * Description: behaves just like PR_WaitCondVar() except timeout is
be9751
  *    in seconds and microseconds instead of PRIntervalTime units.
be9751
  *    If timeout is NULL, this call blocks indefinitely.
be9751
@@ -145,9 +145,26 @@ slapi_destroy_condvar(Slapi_CondVar *cvar)
be9751
 int
be9751
 slapi_wait_condvar(Slapi_CondVar *cvar, struct timeval *timeout)
be9751
 {
be9751
-    /* deprecated in favor of slapi_wait_condvar_pt() which requires that the
be9751
+    /* Deprecated in favor of slapi_wait_condvar_pt() which requires that the
be9751
      * mutex be passed in */
be9751
-    return (0);
be9751
+    PRIntervalTime prit;
be9751
+
be9751
+    if (cvar == NULL) {
be9751
+        return (0);
be9751
+    }
be9751
+
be9751
+    if (timeout == NULL) {
be9751
+        prit = PR_INTERVAL_NO_TIMEOUT;
be9751
+    } else {
be9751
+        prit = PR_SecondsToInterval(timeout->tv_sec) + PR_MicrosecondsToInterval(timeout->tv_usec);
be9751
+    }
be9751
+
be9751
+    if (PR_WaitCondVar((PRCondVar *)cvar, prit) != PR_SUCCESS) {
be9751
+        return (0);
be9751
+    }
be9751
+
be9751
+    return (1);
be9751
+
be9751
 }
be9751
 
be9751
 int
be9751
diff --git a/ldap/servers/slapd/snmp_collator.c b/ldap/servers/slapd/snmp_collator.c
be9751
index 3dd3af657..d760515f4 100644
be9751
--- a/ldap/servers/slapd/snmp_collator.c
be9751
+++ b/ldap/servers/slapd/snmp_collator.c
be9751
@@ -385,8 +385,9 @@ snmp_collator_start()
be9751
     snmp_collator_init();
be9751
 
be9751
     /* Arrange to be called back periodically to update the mmap'd stats file. */
be9751
-    snmp_eq_ctx = slapi_eq_repeat(snmp_collator_update, NULL, (time_t)0,
be9751
-                                  SLAPD_SNMP_UPDATE_INTERVAL);
be9751
+    snmp_eq_ctx = slapi_eq_repeat_rel(snmp_collator_update, NULL,
be9751
+                                      slapi_current_rel_time_t(),
be9751
+                                      SLAPD_SNMP_UPDATE_INTERVAL);
be9751
     return 0;
be9751
 }
be9751
 
be9751
@@ -411,7 +412,7 @@ snmp_collator_stop()
be9751
     }
be9751
 
be9751
     /* Abort any pending events */
be9751
-    slapi_eq_cancel(snmp_eq_ctx);
be9751
+    slapi_eq_cancel_rel(snmp_eq_ctx);
be9751
     snmp_collator_stopped = 1;
be9751
 
be9751
     /* acquire the semaphore */
be9751
diff --git a/ldap/servers/slapd/task.c b/ldap/servers/slapd/task.c
be9751
index 26f281cba..bded287c6 100644
be9751
--- a/ldap/servers/slapd/task.c
be9751
+++ b/ldap/servers/slapd/task.c
be9751
@@ -387,7 +387,7 @@ slapi_task_status_changed(Slapi_Task *task)
be9751
                 ttl = (24*3600); /* be reasonable, allow to check task status not longer than one day  */
be9751
             task->task_flags |= SLAPI_TASK_DESTROYING;
be9751
             /* queue an event to destroy the state info */
be9751
-            slapi_eq_once(destroy_task, (void *)task, slapi_current_rel_time_t() + ttl);
be9751
+            slapi_eq_once_rel(destroy_task, (void *)task, slapi_current_rel_time_t() + ttl);
be9751
         }
be9751
         slapi_free_search_results_internal(pb);
be9751
         slapi_pblock_destroy(pb);
be9751
diff --git a/ldap/servers/slapd/uuid.c b/ldap/servers/slapd/uuid.c
be9751
index a8bd6ee6c..31384a544 100644
be9751
--- a/ldap/servers/slapd/uuid.c
be9751
+++ b/ldap/servers/slapd/uuid.c
be9751
@@ -186,7 +186,8 @@ uuid_init(const char *configDir, const Slapi_DN *configDN, PRBool mtGen)
be9751
 
be9751
     /* schedule update task for multithreaded generation */
be9751
     if (_state.mtGen)
be9751
-        slapi_eq_repeat(uuid_update_state, NULL, (time_t)0, UPDATE_INTERVAL);
be9751
+        slapi_eq_repeat_rel(uuid_update_state, NULL, slapi_current_rel_time_t(),
be9751
+                            UPDATE_INTERVAL);
be9751
 
be9751
     _state.initialized = PR_TRUE;
be9751
     return UUID_SUCCESS;
be9751
-- 
be9751
2.26.2
be9751