1 /*------------------------------------------------------------------------- 2 * 3 * pthread-win32.c 4 * partial pthread implementation for win32 5 * 6 * Copyright (c) 2004-2019, 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 pthread_self(void)18pthread_self(void) 19 { 20 return GetCurrentThreadId(); 21 } 22 23 void pthread_setspecific(pthread_key_t key,void * val)24pthread_setspecific(pthread_key_t key, void *val) 25 { 26 } 27 28 void * pthread_getspecific(pthread_key_t key)29pthread_getspecific(pthread_key_t key) 30 { 31 return NULL; 32 } 33 34 int pthread_mutex_init(pthread_mutex_t * mp,void * attr)35pthread_mutex_init(pthread_mutex_t *mp, void *attr) 36 { 37 *mp = (CRITICAL_SECTION *) malloc(sizeof(CRITICAL_SECTION)); 38 if (!*mp) 39 return 1; 40 InitializeCriticalSection(*mp); 41 return 0; 42 } 43 44 int pthread_mutex_lock(pthread_mutex_t * mp)45pthread_mutex_lock(pthread_mutex_t *mp) 46 { 47 if (!*mp) 48 return 1; 49 EnterCriticalSection(*mp); 50 return 0; 51 } 52 53 int pthread_mutex_unlock(pthread_mutex_t * mp)54pthread_mutex_unlock(pthread_mutex_t *mp) 55 { 56 if (!*mp) 57 return 1; 58 LeaveCriticalSection(*mp); 59 return 0; 60 } 61