00001 /*------------------------------------------------------------------------- 00002 * 00003 * pthread-win32.c 00004 * partial pthread implementation for win32 00005 * 00006 * Copyright (c) 2004-2013, PostgreSQL Global Development Group 00007 * IDENTIFICATION 00008 * src/interfaces/libpq/pthread-win32.c 00009 * 00010 *------------------------------------------------------------------------- 00011 */ 00012 00013 #include "postgres_fe.h" 00014 00015 #include <windows.h> 00016 #include "pthread-win32.h" 00017 00018 DWORD 00019 pthread_self(void) 00020 { 00021 return GetCurrentThreadId(); 00022 } 00023 00024 void 00025 pthread_setspecific(pthread_key_t key, void *val) 00026 { 00027 } 00028 00029 void * 00030 pthread_getspecific(pthread_key_t key) 00031 { 00032 return NULL; 00033 } 00034 00035 int 00036 pthread_mutex_init(pthread_mutex_t *mp, void *attr) 00037 { 00038 *mp = (CRITICAL_SECTION *) malloc(sizeof(CRITICAL_SECTION)); 00039 if (!*mp) 00040 return 1; 00041 InitializeCriticalSection(*mp); 00042 return 0; 00043 } 00044 00045 int 00046 pthread_mutex_lock(pthread_mutex_t *mp) 00047 { 00048 if (!*mp) 00049 return 1; 00050 EnterCriticalSection(*mp); 00051 return 0; 00052 } 00053 00054 int 00055 pthread_mutex_unlock(pthread_mutex_t *mp) 00056 { 00057 if (!*mp) 00058 return 1; 00059 LeaveCriticalSection(*mp); 00060 return 0; 00061 }