Allow non-btree speculative insertion indexes
[pgsql.git] / src / interfaces / libpq / pthread-win32.c
blobdb75d491b90d4c58cc474f5ad7658605bb4b80ef
1 /*-------------------------------------------------------------------------
3 * pthread-win32.c
4 * partial pthread implementation for win32
6 * Copyright (c) 2004-2025, PostgreSQL Global Development Group
7 * IDENTIFICATION
8 * src/interfaces/libpq/pthread-win32.c
10 *-------------------------------------------------------------------------
13 #include "postgres_fe.h"
15 #include "pthread-win32.h"
17 DWORD
18 pthread_self(void)
20 return GetCurrentThreadId();
23 void
24 pthread_setspecific(pthread_key_t key, void *val)
28 void *
29 pthread_getspecific(pthread_key_t key)
31 return NULL;
34 int
35 pthread_mutex_init(pthread_mutex_t *mp, void *attr)
37 mp->initstate = 0;
38 return 0;
41 int
42 pthread_mutex_lock(pthread_mutex_t *mp)
44 /* Initialize the csection if not already done */
45 if (mp->initstate != 1)
47 LONG istate;
49 while ((istate = InterlockedExchange(&mp->initstate, 2)) == 2)
50 Sleep(0); /* wait, another thread is doing this */
51 if (istate != 1)
52 InitializeCriticalSection(&mp->csection);
53 InterlockedExchange(&mp->initstate, 1);
55 EnterCriticalSection(&mp->csection);
56 return 0;
59 int
60 pthread_mutex_unlock(pthread_mutex_t *mp)
62 if (mp->initstate != 1)
63 return EINVAL;
64 LeaveCriticalSection(&mp->csection);
65 return 0;