From: Andreas Beckmann Date: Wed, 1 Dec 2021 22:39:45 +0000 (+0100) Subject: [PATCH 66/90] pthread: add PTHREAD_CHECK() to all pthread_*() calls X-Git-Tag: archive/raspbian/1.8-3+rpi1^2~69 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f135f610669151ba3b15cf084475c279ea5ae221;p=pocl.git [PATCH 66/90] pthread: add PTHREAD_CHECK() to all pthread_*() calls Gbp-Pq: Name 0066-pthread-add-PTHREAD_CHECK-to-all-pthread_-calls.patch --- diff --git a/lib/CL/devices/pthread/pthread.c b/lib/CL/devices/pthread/pthread.c index 9febfb2..444d7dc 100644 --- a/lib/CL/devices/pthread/pthread.c +++ b/lib/CL/devices/pthread/pthread.c @@ -294,8 +294,7 @@ pocl_pthread_join(cl_device_id device, cl_command_queue cq) } else { - int r = pthread_cond_wait (cq_cond, &cq->pocl_lock); - assert (r == 0); + PTHREAD_CHECK (pthread_cond_wait (cq_cond, &cq->pocl_lock)); } } return; @@ -335,15 +334,14 @@ pocl_pthread_notify_cmdq_finished (cl_command_queue cq) * user threads waiting on the same command queue * in pthread_scheduler_wait_cq(). */ pthread_cond_t *cq_cond = (pthread_cond_t *)cq->data; - int r = pthread_cond_broadcast (cq_cond); - assert (r == 0); + PTHREAD_CHECK (pthread_cond_broadcast (cq_cond)); } void pocl_pthread_notify_event_finished (cl_event event) { struct event_data *e_d = event->data; - pthread_cond_broadcast (&e_d->event_cond); + PTHREAD_CHECK (pthread_cond_broadcast (&e_d->event_cond)); } void @@ -355,7 +353,7 @@ pocl_pthread_update_event (cl_device_id device, cl_event event) e_d = malloc(sizeof(struct event_data)); assert(e_d); - pthread_cond_init(&e_d->event_cond, NULL); + PTHREAD_CHECK (pthread_cond_init (&e_d->event_cond, NULL)); event->data = (void *) e_d; } } @@ -367,7 +365,7 @@ void pocl_pthread_wait_event (cl_device_id device, cl_event event) POCL_LOCK_OBJ (event); while (event->status > CL_COMPLETE) { - pthread_cond_wait(&e_d->event_cond, &event->pocl_lock); + PTHREAD_CHECK (pthread_cond_wait (&e_d->event_cond, &event->pocl_lock)); } POCL_UNLOCK_OBJ (event); } @@ -386,8 +384,7 @@ pocl_pthread_init_queue (cl_device_id device, cl_command_queue queue) queue->data = pocl_aligned_malloc (HOST_CPU_CACHELINE_SIZE, sizeof (pthread_cond_t)); pthread_cond_t *cond = (pthread_cond_t *)queue->data; - int r = pthread_cond_init (cond, NULL); - assert (r == 0); + PTHREAD_CHECK (pthread_cond_init (cond, NULL)); return CL_SUCCESS; } @@ -395,8 +392,7 @@ int pocl_pthread_free_queue (cl_device_id device, cl_command_queue queue) { pthread_cond_t *cond = (pthread_cond_t *)queue->data; - int r = pthread_cond_destroy (cond); - assert (r == 0); + PTHREAD_CHECK (pthread_cond_destroy (cond)); POCL_MEM_FREE (queue->data); return CL_SUCCESS; } diff --git a/lib/CL/devices/pthread/pthread_scheduler.c b/lib/CL/devices/pthread/pthread_scheduler.c index f4e8dce..d3a8958 100644 --- a/lib/CL/devices/pthread/pthread_scheduler.c +++ b/lib/CL/devices/pthread/pthread_scheduler.c @@ -88,7 +88,7 @@ pthread_scheduler_init (cl_device_id device) size_t num_worker_threads = device->max_compute_units; POCL_FAST_INIT (scheduler.wq_lock_fast); - pthread_cond_init (&(scheduler.wake_pool), NULL); + PTHREAD_CHECK (pthread_cond_init (&(scheduler.wake_pool), NULL)); scheduler.thread_pool = pocl_aligned_malloc ( HOST_CPU_CACHELINE_SIZE, @@ -109,9 +109,9 @@ pthread_scheduler_init (cl_device_id device) for (i = 0; i < num_worker_threads; ++i) { scheduler.thread_pool[i].index = i; - pthread_create (&scheduler.thread_pool[i].thread, NULL, - pocl_pthread_driver_thread, - (void*)&scheduler.thread_pool[i]); + PTHREAD_CHECK (pthread_create (&scheduler.thread_pool[i].thread, NULL, + pocl_pthread_driver_thread, + (void *)&scheduler.thread_pool[i])); } } @@ -123,17 +123,17 @@ pthread_scheduler_uninit () POCL_FAST_LOCK (scheduler.wq_lock_fast); scheduler.thread_pool_shutdown_requested = 1; - pthread_cond_broadcast (&scheduler.wake_pool); + PTHREAD_CHECK (pthread_cond_broadcast (&scheduler.wake_pool)); POCL_FAST_UNLOCK (scheduler.wq_lock_fast); for (i = 0; i < scheduler.num_threads; ++i) { - pthread_join (scheduler.thread_pool[i].thread, NULL); + PTHREAD_CHECK (pthread_join (scheduler.thread_pool[i].thread, NULL)); } pocl_aligned_free (scheduler.thread_pool); POCL_FAST_DESTROY (scheduler.wq_lock_fast); - pthread_cond_destroy (&scheduler.wake_pool); + PTHREAD_CHECK (pthread_cond_destroy (&scheduler.wake_pool)); scheduler.thread_pool_shutdown_requested = 0; } @@ -144,7 +144,7 @@ void pthread_scheduler_push_command (_cl_command_node *cmd) { POCL_FAST_LOCK (scheduler.wq_lock_fast); DL_APPEND (scheduler.work_queue, cmd); - pthread_cond_broadcast (&scheduler.wake_pool); + PTHREAD_CHECK (pthread_cond_broadcast (&scheduler.wake_pool)); POCL_FAST_UNLOCK (scheduler.wq_lock_fast); } @@ -153,7 +153,7 @@ pthread_scheduler_push_kernel (kernel_run_command *run_cmd) { POCL_FAST_LOCK (scheduler.wq_lock_fast); DL_APPEND (scheduler.kernel_queue, run_cmd); - pthread_cond_broadcast (&scheduler.wake_pool); + PTHREAD_CHECK (pthread_cond_broadcast (&scheduler.wake_pool)); POCL_FAST_UNLOCK (scheduler.wq_lock_fast); } @@ -486,7 +486,8 @@ RETRY: /* if neither a command nor a kernel was available, sleep */ if ((cmd == NULL) && (run_cmd == NULL) && (do_exit == 0)) { - pthread_cond_wait (&scheduler.wake_pool, &scheduler.wq_lock_fast); + PTHREAD_CHECK ( + pthread_cond_wait (&scheduler.wake_pool, &scheduler.wq_lock_fast)); goto RETRY; } @@ -521,7 +522,8 @@ pocl_pthread_driver_thread (void *p) cpu_set_t set; CPU_ZERO (&set); CPU_SET (td->index, &set); - pthread_setaffinity_np (td->thread, sizeof (cpu_set_t), &set); + PTHREAD_CHECK ( + pthread_setaffinity_np (td->thread, sizeof (cpu_set_t), &set)); } #endif diff --git a/lib/CL/devices/pthread/pthread_utils.c b/lib/CL/devices/pthread/pthread_utils.c index a0894eb..9ff2460 100644 --- a/lib/CL/devices/pthread/pthread_utils.c +++ b/lib/CL/devices/pthread/pthread_utils.c @@ -62,21 +62,21 @@ kernel_run_command* new_kernel_run_command () { LL_DELETE (kernel_pool, k); memset (k, 0, sizeof(kernel_run_command)); - pthread_mutex_init(&k->lock, NULL); + PTHREAD_CHECK (pthread_mutex_init (&k->lock, NULL)); POCL_UNLOCK (kernel_pool_lock); return k; } POCL_UNLOCK (kernel_pool_lock); k = (kernel_run_command*)calloc (1, sizeof (kernel_run_command)); - pthread_mutex_init (&k->lock, NULL); + PTHREAD_CHECK (pthread_mutex_init (&k->lock, NULL)); return k; } void free_kernel_run_command (kernel_run_command *k) { POCL_LOCK (kernel_pool_lock); - pthread_mutex_destroy (&k->lock); + PTHREAD_CHECK (pthread_mutex_destroy (&k->lock)); LL_PREPEND (kernel_pool, k); POCL_UNLOCK (kernel_pool_lock); }