wfcqueue: allow defining CDS_WFCQ_WAIT_SLEEP to override `poll'
authorEric Wong <normalperson@yhbt.net>
Wed, 1 Aug 2018 18:54:45 +0000 (18:54 +0000)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 20 Aug 2018 19:47:20 +0000 (15:47 -0400)
Users may want to use alternative sleeping behavior instead of
`poll'.  Make CDS_WFCQ_WAIT_SLEEP a macro which may be defined
before including wfcqueue.h.

This alternative behavior could include logging, performing
low-priority cleanup work, sleeping a shorter/longer interval
or any combination of that.

This will also make integration into glibc easier, as `poll'
linkage causes conformance test failures even when relegated
to an impossible code path:
https://public-inbox.org/libc-alpha/20180801092626.jrwyrojfye4avcis@whir/

Signed-off-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/urcu/static/wfcqueue.h

index 67ac05ffd15e384dc42317e0d5b4d0c93d71c2d6..eae074323479bfc729ad8e06983a38b3407ec316 100644 (file)
@@ -223,6 +223,23 @@ static inline bool _cds_wfcq_enqueue(cds_wfcq_head_ptr_t head,
        return ___cds_wfcq_append(head, tail, new_tail, new_tail);
 }
 
        return ___cds_wfcq_append(head, tail, new_tail, new_tail);
 }
 
+/*
+ * CDS_WFCQ_WAIT_SLEEP:
+ *
+ * By default, this sleeps for the given @msec milliseconds.
+ * This is a macro which LGPL users may #define themselves before
+ * including wfcqueue.h to override the default behavior (e.g.
+ * to log a warning or perform other background work).
+ */
+#ifndef CDS_WFCQ_WAIT_SLEEP
+#define CDS_WFCQ_WAIT_SLEEP(msec) ___cds_wfcq_wait_sleep(msec)
+#endif
+
+static inline void ___cds_wfcq_wait_sleep(int msec)
+{
+       (void) poll(NULL, 0, msec);
+}
+
 /*
  * ___cds_wfcq_busy_wait: adaptative busy-wait.
  *
 /*
  * ___cds_wfcq_busy_wait: adaptative busy-wait.
  *
@@ -234,7 +251,7 @@ ___cds_wfcq_busy_wait(int *attempt, int blocking)
        if (!blocking)
                return 1;
        if (++(*attempt) >= WFCQ_ADAPT_ATTEMPTS) {
        if (!blocking)
                return 1;
        if (++(*attempt) >= WFCQ_ADAPT_ATTEMPTS) {
-               (void) poll(NULL, 0, WFCQ_WAIT);        /* Wait for 10ms */
+               CDS_WFCQ_WAIT_SLEEP(WFCQ_WAIT);         /* Wait for 10ms */
                *attempt = 0;
        } else {
                caa_cpu_relax();
                *attempt = 0;
        } else {
                caa_cpu_relax();
This page took 0.025409 seconds and 4 git commands to generate.