[PATCH 69/90] add PTHREAD_CHECK2() accepting an additional non-zero return code
authorAndreas Beckmann <anbe@debian.org>
Fri, 3 Dec 2021 15:14:53 +0000 (16:14 +0100)
committerAndreas Beckmann <anbe@debian.org>
Fri, 7 Jan 2022 23:55:22 +0000 (23:55 +0000)
use e.g. for
* pthread_broadcast(): PTHREAD_BARRIER_SERIAL_THREAD
* pthread_cond_timedwait(): ETIMEDOUT

avoid the extra function call to the error handler if the command succeeded

Gbp-Pq: Name 0069-add-PTHREAD_CHECK2-accepting-an-additional-non-zero-.patch

lib/CL/pocl_cl.h

index 0b3f0960f9d963f94b224b7df5e0e66d8dbf44e1..7d36ca3ce9608fe0a8cc4a2afd06acce80bbbadb 100644 (file)
@@ -115,8 +115,20 @@ void pocl_abort_on_pthread_error (int status, unsigned line, const char *func);
 }
 #endif
 
-#define PTHREAD_CHECK(code)                                                   \
-  pocl_abort_on_pthread_error ((code), __LINE__, __FUNCTION__);
+/* Some pthread_*() calls may return '0' or a specific non-zero value on
+ * success.
+ */
+#define PTHREAD_CHECK2(_status_ok, _code)                                     \
+  do                                                                          \
+    {                                                                         \
+      int _pthread_status = (_code);                                          \
+      if (_pthread_status != 0 && _pthread_status != (_status_ok))            \
+        pocl_abort_on_pthread_error (_pthread_status, __LINE__,               \
+                                     __FUNCTION__);                           \
+    }                                                                         \
+  while (0)
+
+#define PTHREAD_CHECK(code) PTHREAD_CHECK2 (0, code)
 
 /* Generic functionality for handling different types of 
    OpenCL (host) objects. */