1 /*-------------------------------------------------------------------------
4 * partial pthread implementation for win32
6 * Copyright (c) 2004-2025, PostgreSQL Global Development Group
8 * src/interfaces/libpq/pthread-win32.c
10 *-------------------------------------------------------------------------
13 #include "postgres_fe.h"
15 #include "pthread-win32.h"
20 return GetCurrentThreadId();
24 pthread_setspecific(pthread_key_t key
, void *val
)
29 pthread_getspecific(pthread_key_t key
)
35 pthread_mutex_init(pthread_mutex_t
*mp
, void *attr
)
42 pthread_mutex_lock(pthread_mutex_t
*mp
)
44 /* Initialize the csection if not already done */
45 if (mp
->initstate
!= 1)
49 while ((istate
= InterlockedExchange(&mp
->initstate
, 2)) == 2)
50 Sleep(0); /* wait, another thread is doing this */
52 InitializeCriticalSection(&mp
->csection
);
53 InterlockedExchange(&mp
->initstate
, 1);
55 EnterCriticalSection(&mp
->csection
);
60 pthread_mutex_unlock(pthread_mutex_t
*mp
)
62 if (mp
->initstate
!= 1)
64 LeaveCriticalSection(&mp
->csection
);