PostgreSQL Source Code  git master
pthread-win32.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 *
3 * pthread-win32.c
4 * partial pthread implementation for win32
5 *
6 * Copyright (c) 2004-2024, PostgreSQL Global Development Group
7 * IDENTIFICATION
8 * src/interfaces/libpq/pthread-win32.c
9 *
10 *-------------------------------------------------------------------------
11 */
12 
13 #include "postgres_fe.h"
14 
15 #include "pthread-win32.h"
16 
17 DWORD
19 {
20  return GetCurrentThreadId();
21 }
22 
23 void
25 {
26 }
27 
28 void *
30 {
31  return NULL;
32 }
33 
34 int
36 {
37  mp->initstate = 0;
38  return 0;
39 }
40 
41 int
43 {
44  /* Initialize the csection if not already done */
45  if (mp->initstate != 1)
46  {
47  LONG istate;
48 
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);
54  }
55  EnterCriticalSection(&mp->csection);
56  return 0;
57 }
58 
59 int
61 {
62  if (mp->initstate != 1)
63  return EINVAL;
64  LeaveCriticalSection(&mp->csection);
65  return 0;
66 }
long val
Definition: informix.c:670
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:60
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
int pthread_mutex_lock(pthread_mutex_t *mp)
Definition: pthread-win32.c:42
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
DWORD pthread_self(void)
Definition: pthread-win32.c:18
int pthread_mutex_init(pthread_mutex_t *mp, void *attr)
Definition: pthread-win32.c:35
ULONG pthread_key_t
Definition: pthread-win32.h:7
CRITICAL_SECTION csection
Definition: pthread-win32.h:13