[PATCH 66/90] pthread: add PTHREAD_CHECK() to all pthread_*() calls
authorAndreas Beckmann <anbe@debian.org>
Wed, 1 Dec 2021 22:39:45 +0000 (23:39 +0100)
committerAndreas Beckmann <anbe@debian.org>
Fri, 7 Jan 2022 23:55:22 +0000 (23:55 +0000)
Gbp-Pq: Name 0066-pthread-add-PTHREAD_CHECK-to-all-pthread_-calls.patch

lib/CL/devices/pthread/pthread.c
lib/CL/devices/pthread/pthread_scheduler.c
lib/CL/devices/pthread/pthread_utils.c

index 9febfb26ab89574f67d1e089ab88bb7aaa930853..444d7dc9eb2ed5080af7c9ec601c733687cfd79b 100644 (file)
@@ -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;
 }
index f4e8dcebdb5a19eca3d44d41927b2334767eb1fe..d3a895861ac2934d8ac8c594bab08c6a74ebf568 100644 (file)
@@ -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
 
index a0894eb9e1d8f71518a917308263257863cd738d..9ff246037f48a01e8e55d5ad991ddd08a0431f3a 100644 (file)
@@ -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);
 }