Debian Codegraph @

src/include/port/pg_pthread.h

raw
1 /*-------------------------------------------------------------------------
2 *
3 * Declarations for missing POSIX thread components.
4 *
5 * Currently this supplies an implementation of pthread_barrier_t for the
6 * benefit of macOS, which lacks it. These declarations are not in port.h,
7 * because that'd require <pthread.h> to be included by every translation
8 * unit.
9 *
10 *-------------------------------------------------------------------------
11 */
12
13 #ifndef PG_PTHREAD_H
14 #define PG_PTHREAD_H
15
16 #include <pthread.h> /* IWYU pragma: export */
17
18 #ifndef HAVE_PTHREAD_BARRIER_WAIT
19
20 #ifndef PTHREAD_BARRIER_SERIAL_THREAD
21 #define PTHREAD_BARRIER_SERIAL_THREAD (-1)
22 #endif
23
24 typedef struct pg_pthread_barrier
25 {
26 bool sense; /* we only need a one bit phase */
27 int count; /* number of threads expected */
28 int arrived; /* number of threads that have arrived */
29 pthread_mutex_t mutex;
30 pthread_cond_t cond;
31 } pthread_barrier_t;
32
33 extern int pthread_barrier_init(pthread_barrier_t *barrier,
34 const void *attr,
35 int count);
36 extern int pthread_barrier_wait(pthread_barrier_t *barrier);
37 extern int pthread_barrier_destroy(pthread_barrier_t *barrier);
38
39 #endif
40
41 #endif