[PATCH 71/90] add PTHREAD_CHECK() to all macros wrapping pthread_*() calls
authorAndreas Beckmann <anbe@debian.org>
Thu, 2 Dec 2021 01:34:09 +0000 (02:34 +0100)
committerAndreas Beckmann <anbe@debian.org>
Fri, 7 Jan 2022 23:55:22 +0000 (23:55 +0000)
Gbp-Pq: Name 0071-add-PTHREAD_CHECK-to-all-macros-wrapping-pthread_-ca.patch

lib/CL/pocl_cl.h

index 7d36ca3ce9608fe0a8cc4a2afd06acce80bbbadb..27ef39877d178e7d4e0e294b2522ea774a7ccaeb 100644 (file)
@@ -28,6 +28,7 @@
 #include "config.h"
 
 #include <assert.h>
+#include <errno.h>
 #include <stdio.h>
 
 #ifdef HAVE_VALGRIND
@@ -133,37 +134,15 @@ void pocl_abort_on_pthread_error (int status, unsigned line, const char *func);
 /* Generic functionality for handling different types of 
    OpenCL (host) objects. */
 
-#define POCL_LOCK(__LOCK__)                                                   \
-  do                                                                          \
-    {                                                                         \
-      int r = pthread_mutex_lock (&(__LOCK__));                               \
-      assert (r == 0);                                                        \
-    }                                                                         \
-  while (0)
+#define POCL_LOCK(__LOCK__) PTHREAD_CHECK (pthread_mutex_lock (&(__LOCK__)))
 #define POCL_UNLOCK(__LOCK__)                                                 \
-  do                                                                          \
-    {                                                                         \
-      int r = pthread_mutex_unlock (&(__LOCK__));                             \
-      assert (r == 0);                                                        \
-    }                                                                         \
-  while (0)
+  PTHREAD_CHECK (pthread_mutex_unlock (&(__LOCK__)))
 #define POCL_INIT_LOCK(__LOCK__)                                              \
-  do                                                                          \
-    {                                                                         \
-      int r = pthread_mutex_init (&(__LOCK__), NULL);                         \
-      assert (r == 0);                                                        \
-    }                                                                         \
-  while (0)
+  PTHREAD_CHECK (pthread_mutex_init (&(__LOCK__), NULL))
 /* We recycle OpenCL objects by not actually freeing them until the
-   very end. Thus, the lock should not be destoryed at the refcount 0. */
+   very end. Thus, the lock should not be destroyed at the refcount 0. */
 #define POCL_DESTROY_LOCK(__LOCK__)                                           \
-  do                                                                          \
-    {                                                                         \
-      int r = pthread_mutex_destroy (&(__LOCK__));                            \
-      assert (r == 0);                                                        \
-    }                                                                         \
-  while (0)
-
+  PTHREAD_CHECK (pthread_mutex_destroy (&(__LOCK__)))
 
 /* If available, use an Adaptive mutex for locking in the pthread driver,
    otherwise fallback to simple mutexes */
@@ -176,10 +155,10 @@ void pocl_abort_on_pthread_error (int status, unsigned line, const char *func);
     do { \
       pthread_mutexattr_t attrs; \
       pthread_mutexattr_init (&attrs); \
-      int r = pthread_mutexattr_settype (&attrs, PTHREAD_MUTEX_ADAPTIVE_NP); \
-      assert (r == 0); \
-      pthread_mutex_init(&l, &attrs); \
-      pthread_mutexattr_destroy(&attrs);\
+      PTHREAD_CHECK (                                                         \
+          pthread_mutexattr_settype (&attrs, PTHREAD_MUTEX_ADAPTIVE_NP));     \
+      PTHREAD_CHECK (pthread_mutex_init (&l, &attrs));                        \
+      PTHREAD_CHECK (pthread_mutexattr_destroy (&attrs));                     \
     } while (0)
 #else
 #define POCL_FAST_INIT(l) POCL_INIT_LOCK (l)
@@ -187,17 +166,18 @@ void pocl_abort_on_pthread_error (int status, unsigned line, const char *func);
 
 #define POCL_FAST_DESTROY(l) POCL_DESTROY_LOCK(l)
 
-#define POCL_INIT_COND(c) pthread_cond_init (&c, NULL)
-#define POCL_DESTROY_COND(c) pthread_cond_destroy (&c)
-#define POCL_SIGNAL_COND(c) pthread_cond_signal (&c)
-#define POCL_BROADCAST_COND(c) pthread_cond_broadcast (&c)
-#define POCL_WAIT_COND(c, m) pthread_cond_wait (&c, &m)
-#define POCL_TIMEDWAIT_COND(c, m, t) pthread_cond_timedwait (&c, &m, &t)
+#define POCL_INIT_COND(c) PTHREAD_CHECK (pthread_cond_init (&c, NULL))
+#define POCL_DESTROY_COND(c) PTHREAD_CHECK (pthread_cond_destroy (&c))
+#define POCL_SIGNAL_COND(c) PTHREAD_CHECK (pthread_cond_signal (&c))
+#define POCL_BROADCAST_COND(c) PTHREAD_CHECK (pthread_cond_broadcast (&c))
+#define POCL_WAIT_COND(c, m) PTHREAD_CHECK (pthread_cond_wait (&c, &m))
+#define POCL_TIMEDWAIT_COND(c, m, t) PTHREAD_CHECK2(ETIMEDOUT, pthread_cond_timedwait (&c, &m, &t))
 
 #define POCL_CREATE_THREAD(thr, func, arg)                                    \
-  pthread_create (&thr, NULL, func, arg)
-#define POCL_JOIN_THREAD(thr) pthread_join (thr, NULL)
-#define POCL_JOIN_THREAD2(thr, res_ptr) pthread_join (thr, res_ptr)
+  PTHREAD_CHECK (pthread_create (&thr, NULL, func, arg))
+#define POCL_JOIN_THREAD(thr) PTHREAD_CHECK (pthread_join (thr, NULL))
+#define POCL_JOIN_THREAD2(thr, res_ptr)                                       \
+  PTHREAD_CHECK (pthread_join (thr, res_ptr))
 #define POCL_EXIT_THREAD(res) pthread_exit (res)
 
 //############################################################################