summaryrefslogtreecommitdiff
path: root/src/include/port/pg_pthread.h
diff options
context:
space:
mode:
authorThomas Munro2021-03-10 02:40:17 +0000
committerThomas Munro2021-03-10 04:44:04 +0000
commit44bf3d5083e151d772c5d6f656e3e162f573dced (patch)
tree9f2781e6f02ea80702d526babff64726197b51ec /src/include/port/pg_pthread.h
parent547f04e7348b6ed992bd4a197d39661fe7c25097 (diff)
Add missing pthread_barrier_t.
Supply a simple implementation of the missing pthread_barrier_t type and functions, for macOS. Discussion: https://postgr.es/m/20200227180100.zyvjwzcpiokfsqm2%40alap3.anarazel.de
Diffstat (limited to 'src/include/port/pg_pthread.h')
-rw-r--r--src/include/port/pg_pthread.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/include/port/pg_pthread.h b/src/include/port/pg_pthread.h
new file mode 100644
index 00000000000..d102ce9d6f3
--- /dev/null
+++ b/src/include/port/pg_pthread.h
@@ -0,0 +1,41 @@
+/*-------------------------------------------------------------------------
+ *
+ * Declarations for missing POSIX thread components.
+ *
+ * Currently this supplies an implementation of pthread_barrier_t for the
+ * benefit of macOS, which lacks it. These declarations are not in port.h,
+ * because that'd require <pthread.h> to be included by every translation
+ * unit.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#ifndef PG_PTHREAD_H
+#define PG_PTHREAD_H
+
+#include <pthread.h>
+
+#ifndef HAVE_PTHREAD_BARRIER_WAIT
+
+#ifndef PTHREAD_BARRIER_SERIAL_THREAD
+#define PTHREAD_BARRIER_SERIAL_THREAD (-1)
+#endif
+
+typedef struct pg_pthread_barrier
+{
+ bool sense; /* we only need a one bit phase */
+ int count; /* number of threads expected */
+ int arrived; /* number of threads that have arrived */
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+} pthread_barrier_t;
+
+extern int pthread_barrier_init(pthread_barrier_t *barrier,
+ const void *attr,
+ int count);
+extern int pthread_barrier_wait(pthread_barrier_t *barrier);
+extern int pthread_barrier_destroy(pthread_barrier_t *barrier);
+
+#endif
+
+#endif