Fix error handling in replacement pthread_barrier_init().
authorThomas Munro
Mon, 31 May 2021 23:22:22 +0000 (11:22 +1200)
committerThomas Munro
Mon, 31 May 2021 23:31:06 +0000 (11:31 +1200)
Commit 44bf3d50 incorrectly used an errno-style interface when supplying
missing pthread functionality (i.e. on macOS), but it should check for
and return error numbers directly.

src/port/pthread_barrier_wait.c

index 7ca8e2ce0be0cd9516694620ecb0807217f020c8..8282cc5b89d5cc890f40e215eeb2a598a20c5018 100644 (file)
 int
 pthread_barrier_init(pthread_barrier_t *barrier, const void *attr, int count)
 {
+   int         error;
+
    barrier->sense = false;
    barrier->count = count;
    barrier->arrived = 0;
-   if (pthread_cond_init(&barrier->cond, NULL) < 0)
-       return -1;
-   if (pthread_mutex_init(&barrier->mutex, NULL) < 0)
+   if ((error = pthread_cond_init(&barrier->cond, NULL)) != 0)
+       return error;
+   if ((error = pthread_mutex_init(&barrier->mutex, NULL)) != 0)
    {
-       int         save_errno = errno;
-
        pthread_cond_destroy(&barrier->cond);
-       errno = save_errno;
-
-       return -1;
+       return error;
    }
 
    return 0;