pg_pthread.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #ifndef PG_PTHREAD_H
  13. #define PG_PTHREAD_H
  14. #include <pthread.h>
  15. #ifndef HAVE_PTHREAD_BARRIER_WAIT
  16. #ifndef PTHREAD_BARRIER_SERIAL_THREAD
  17. #define PTHREAD_BARRIER_SERIAL_THREAD (-1)
  18. #endif
  19. typedef struct pg_pthread_barrier
  20. {
  21. bool sense; /* we only need a one bit phase */
  22. int count; /* number of threads expected */
  23. int arrived; /* number of threads that have arrived */
  24. pthread_mutex_t mutex;
  25. pthread_cond_t cond;
  26. } pthread_barrier_t;
  27. extern int pthread_barrier_init(pthread_barrier_t *barrier,
  28. const void *attr,
  29. int count);
  30. extern int pthread_barrier_wait(pthread_barrier_t *barrier);
  31. extern int pthread_barrier_destroy(pthread_barrier_t *barrier);
  32. #endif
  33. #endif