| 1 | /* |
| 2 | * Copyright 2015 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * Authors: |
| 20 | * Martin Preisler <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #ifndef OSCAP_COMPAT_PTHREAD_BARRIER_H_ |
| 24 | #define OSCAP_COMPAT_PTHREAD_BARRIER_H_ |
| 25 | |
| 26 | #include "oscap_platforms.h" |
| 27 | |
| 28 | /* |
| 29 | * This file implements a very slow and basic pthread_barrier_t |
| 30 | * on systems where this implementation isn't available. |
| 31 | * |
| 32 | * One such commonly used system is Apple MacOS X. |
| 33 | */ |
| 34 | |
| 35 | #include <pthread.h> |
| 36 | |
| 37 | // TODO: Maybe there is a better macro to check here |
| 38 | #ifdef OS_APPLE |
| 39 | |
| 40 | // returned to the last thread that hits the trip count |
| 41 | #define PTHREAD_BARRIER_SERIAL_THREAD -1 |
| 42 | // 0 is returned to all the other threads that have been waiting |
| 43 | |
| 44 | typedef int pthread_barrierattr_t; |
| 45 | |
| 46 | typedef struct |
| 47 | { |
| 48 | pthread_mutex_t mutex; |
| 49 | pthread_cond_t cond; |
| 50 | int count; |
| 51 | int trip_count; |
| 52 | } pthread_barrier_t; |
| 53 | |
| 54 | int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count); |
| 55 | int pthread_barrier_destroy(pthread_barrier_t *barrier); |
| 56 | int pthread_barrier_wait(pthread_barrier_t *barrier); |
| 57 | |
| 58 | #endif |
| 59 | |
| 60 | #endif |