From 1dff083616a7c5612239da275f8e26e41b048087 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Thu, 2 Dec 2021 02:34:09 +0100 Subject: [PATCH] [PATCH 71/90] add PTHREAD_CHECK() to all macros wrapping pthread_*() calls Gbp-Pq: Name 0071-add-PTHREAD_CHECK-to-all-macros-wrapping-pthread_-ca.patch --- lib/CL/pocl_cl.h | 60 ++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/lib/CL/pocl_cl.h b/lib/CL/pocl_cl.h index 7d36ca3..27ef398 100644 --- a/lib/CL/pocl_cl.h +++ b/lib/CL/pocl_cl.h @@ -28,6 +28,7 @@ #include "config.h" #include +#include #include #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) //############################################################################ -- 2.30.2