summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/include/ecpg-pthread-win32.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
commit46651ce6fe013220ed397add242004d764fc0153 (patch)
tree6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/interfaces/ecpg/include/ecpg-pthread-win32.h
parentInitial commit. (diff)
downloadpostgresql-14-upstream.tar.xz
postgresql-14-upstream.zip
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/interfaces/ecpg/include/ecpg-pthread-win32.h')
-rw-r--r--src/interfaces/ecpg/include/ecpg-pthread-win32.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/include/ecpg-pthread-win32.h b/src/interfaces/ecpg/include/ecpg-pthread-win32.h
new file mode 100644
index 0000000..33c897b
--- /dev/null
+++ b/src/interfaces/ecpg/include/ecpg-pthread-win32.h
@@ -0,0 +1,58 @@
+/* src/interfaces/ecpg/include/ecpg-pthread-win32.h */
+/*
+ * pthread mapping macros for win32 native thread implementation
+ */
+#ifndef _ECPG_PTHREAD_WIN32_H
+#define _ECPG_PTHREAD_WIN32_H
+
+#ifdef ENABLE_THREAD_SAFETY
+
+#ifndef WIN32
+
+#include <pthread.h>
+#else
+
+typedef struct pthread_mutex_t
+{
+ HANDLE handle;
+ LONG initlock;
+} pthread_mutex_t;
+
+typedef DWORD pthread_key_t;
+typedef bool pthread_once_t;
+
+#define PTHREAD_MUTEX_INITIALIZER { NULL, 0 }
+#define PTHREAD_ONCE_INIT false
+
+void win32_pthread_mutex(volatile pthread_mutex_t *mutex);
+void win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void));
+
+#define pthread_mutex_lock(mutex) \
+ do { \
+ if ((mutex)->handle == NULL) \
+ win32_pthread_mutex((mutex)); \
+ WaitForSingleObject((mutex)->handle, INFINITE); \
+ } while(0)
+
+#define pthread_mutex_unlock(mutex) \
+ ReleaseMutex((mutex)->handle)
+
+#define pthread_getspecific(key) \
+ TlsGetValue((key))
+
+#define pthread_setspecific(key, value) \
+ TlsSetValue((key), (value))
+
+/* FIXME: destructor is never called in Win32. */
+#define pthread_key_create(key, destructor) \
+ do { *(key) = TlsAlloc(); ((void)(destructor)); } while(0)
+
+#define pthread_once(once, fn) \
+ do { \
+ if (!*(once)) \
+ win32_pthread_once((once), (fn)); \
+ } while(0)
+#endif /* WIN32 */
+#endif /* ENABLE_THREAD_SAFETY */
+
+#endif /* _ECPG_PTHREAD_WIN32_H */