Fix: workqueue: remove unused variable "ret"
[urcu.git] / src / workqueue.c
index 39d0e077acc101b5e1588c9a1fae954050bd134c..46b097273772dfaa1d29508b6995e4be48471527 100644 (file)
 #include <sched.h>
 
 #include "compat-getcpu.h"
-#include "urcu/wfcqueue.h"
-#include "urcu-pointer.h"
-#include "urcu/list.h"
-#include "urcu/futex.h"
-#include "urcu/tls-compat.h"
-#include "urcu/ref.h"
+#include <urcu/wfcqueue.h>
+#include <urcu/pointer.h>
+#include <urcu/list.h>
+#include <urcu/futex.h>
+#include <urcu/tls-compat.h>
+#include <urcu/ref.h>
 #include "urcu-die.h"
 
 #include "workqueue.h"
@@ -92,7 +92,7 @@ struct urcu_workqueue_completion_work {
  * Losing affinity can be caused by CPU hotunplug/hotplug, or by
  * cpuset(7).
  */
-#if HAVE_SCHED_SETAFFINITY
+#ifdef HAVE_SCHED_SETAFFINITY
 static int set_thread_cpu_affinity(struct urcu_workqueue *workqueue)
 {
        cpu_set_t mask;
@@ -124,7 +124,7 @@ static int set_thread_cpu_affinity(struct urcu_workqueue *workqueue)
        return ret;
 }
 #else
-static int set_thread_cpu_affinity(struct urcu_workqueue *workqueue)
+static int set_thread_cpu_affinity(struct urcu_workqueue *workqueue __attribute__((unused)))
 {
        return 0;
 }
@@ -134,16 +134,25 @@ static void futex_wait(int32_t *futex)
 {
        /* Read condition before read futex */
        cmm_smp_mb();
-       if (uatomic_read(futex) != -1)
-               return;
-       while (futex_async(futex, FUTEX_WAIT, -1, NULL, NULL, 0)) {
+       while (uatomic_read(futex) == -1) {
+               if (!futex_async(futex, FUTEX_WAIT, -1, NULL, NULL, 0)) {
+                       /*
+                        * Prior queued wakeups queued by unrelated code
+                        * using the same address can cause futex wait to
+                        * return 0 even through the futex value is still
+                        * -1 (spurious wakeups). Check the value again
+                        * in user-space to validate whether it really
+                        * differs from -1.
+                        */
+                       continue;
+               }
                switch (errno) {
-               case EWOULDBLOCK:
+               case EAGAIN:
                        /* Value already changed. */
                        return;
                case EINTR:
                        /* Retry if interrupted by signal. */
-                       break;  /* Get out of switch. */
+                       break;  /* Get out of switch. Check again. */
                default:
                        /* Unexpected error. */
                        urcu_die(errno);
@@ -246,7 +255,10 @@ static void *workqueue_thread(void *arg)
                                cmm_smp_mb();
                        }
                } else {
-                       (void) poll(NULL, 0, 10);
+                       if (cds_wfcq_empty(&workqueue->cbs_head,
+                                       &workqueue->cbs_tail)) {
+                               (void) poll(NULL, 0, 10);
+                       }
                }
                if (workqueue->worker_after_wake_up_fct)
                        workqueue->worker_after_wake_up_fct(workqueue, workqueue->priv);
This page took 0.024544 seconds and 4 git commands to generate.