uatomic: Specify complete types for atomic function calls
[userspace-rcu.git] / urcu-defer-impl.h
index f65e41086022f2613bdaf251611a378afb6e5a3d..8f1e5a52c7a9bf769ef0f2224c8d0872a7a89648 100644 (file)
@@ -49,6 +49,7 @@
 #include <urcu/list.h>
 #include <urcu/system.h>
 #include <urcu/tls-compat.h>
+#include "urcu-die.h"
 
 /*
  * Number of entries in the per-thread defer queue. Must be power of 2.
@@ -141,17 +142,12 @@ static void mutex_lock_defer(pthread_mutex_t *mutex)
 
 #ifndef DISTRUST_SIGNALS_EXTREME
        ret = pthread_mutex_lock(mutex);
-       if (ret) {
-               perror("Error in pthread mutex lock");
-               exit(-1);
-       }
+       if (ret)
+               urcu_die(ret);
 #else /* #ifndef DISTRUST_SIGNALS_EXTREME */
        while ((ret = pthread_mutex_trylock(mutex)) != 0) {
-               if (ret != EBUSY && ret != EINTR) {
-                       printf("ret = %d, errno = %d\n", ret, errno);
-                       perror("Error in pthread mutex lock");
-                       exit(-1);
-               }
+               if (ret != EBUSY && ret != EINTR)
+                       urcu_die(ret);
                poll(NULL,0,10);
        }
 #endif /* #else #ifndef DISTRUST_SIGNALS_EXTREME */
@@ -164,8 +160,9 @@ static void wake_up_defer(void)
 {
        if (caa_unlikely(uatomic_read(&defer_thread_futex) == -1)) {
                uatomic_set(&defer_thread_futex, 0);
-               futex_noasync(&defer_thread_futex, FUTEX_WAKE, 1,
-                     NULL, NULL, 0);
+               if (futex_noasync(&defer_thread_futex, FUTEX_WAKE, 1,
+                               NULL, NULL, 0) < 0)
+                       urcu_die(errno);
        }
 }
 
@@ -202,9 +199,22 @@ static void wait_defer(void)
                uatomic_set(&defer_thread_futex, 0);
        } else {
                cmm_smp_rmb();  /* Read queue before read futex */
-               if (uatomic_read(&defer_thread_futex) == -1)
-                       futex_noasync(&defer_thread_futex, FUTEX_WAIT, -1,
-                             NULL, NULL, 0);
+               if (uatomic_read(&defer_thread_futex) != -1)
+                       return;
+               while (futex_noasync(&defer_thread_futex, FUTEX_WAIT, -1,
+                               NULL, NULL, 0)) {
+                       switch (errno) {
+                       case EWOULDBLOCK:
+                               /* Value already changed. */
+                               return;
+                       case EINTR:
+                               /* Retry if interrupted by signal. */
+                               break;  /* Get out of switch. */
+                       default:
+                               /* Unexpected error. */
+                               urcu_die(errno);
+                       }
+               }
        }
 }
 
This page took 0.023771 seconds and 4 git commands to generate.