fix: handle EINTR correctly in get_cpu_mask_from_sysfs
[userspace-rcu.git] / src / workqueue.c
index 72170012eafc2fb925f885b9a666be610901ec3f..5f806c17f7ebc36228b0ceea4d213bf71233db1d 100644 (file)
@@ -121,7 +121,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;
 }
@@ -131,16 +131,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);
@@ -378,7 +387,7 @@ struct urcu_workqueue_completion *urcu_workqueue_create_completion(void)
 {
        struct urcu_workqueue_completion *completion;
 
-       completion = calloc(sizeof(*completion), 1);
+       completion = calloc(1, sizeof(*completion));
        if (!completion)
                urcu_die(errno);
        urcu_ref_set(&completion->ref, 1);
@@ -409,7 +418,7 @@ void urcu_workqueue_queue_completion(struct urcu_workqueue *workqueue,
 {
        struct urcu_workqueue_completion_work *work;
 
-       work = calloc(sizeof(*work), 1);
+       work = calloc(1, sizeof(*work));
        if (!work)
                urcu_die(errno);
        work->completion = completion;
This page took 0.025339 seconds and 4 git commands to generate.