2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis
18 /***********************************************************************
19 * GetCurrentThreadId (KERNEL32.200)
22 int GetCurrentThreadId(void)
27 /***********************************************************************
28 * GetThreadContext (KERNEL32.294)
30 BOOL GetThreadContext(HANDLE hThread, void *lpContext)
34 /***********************************************************************
35 * GetCurrentThread (KERNEL32.200)
37 HANDLE GetCurrentThread(void)
42 /**********************************************************************
43 * Critical Sections are currently ignored
45 void InitializeCriticalSection(CRITICAL_SECTION *lpCrit)
47 memset(lpCrit,0,sizeof(CRITICAL_SECTION));
50 void EnterCriticalSection(CRITICAL_SECTION* lpCrit)
52 if (lpCrit->LockCount)
53 fprintf( stderr, "Error: re-entering critical section %08lx\n",
58 void LeaveCriticalSection(CRITICAL_SECTION* lpCrit)
60 if (!lpCrit->LockCount)
61 fprintf( stderr, "Error: leaving critical section %08lx again\n",
66 void DeleteCriticalSection(CRITICAL_SECTION* lpCrit)
71 /***********************************************************************
72 * Tls is available only for the single thread
75 static int TlsCount=0;
81 Tls=xmalloc(sizeof(LPVOID));
82 /* Tls needs to be zero initialized */
86 Tls=xrealloc(Tls,sizeof(LPVOID)*(++TlsCount));
91 void TlsFree(DWORD index)
93 /*FIXME: should remember that it has been freed */
97 LPVOID TlsGetValue(DWORD index)
101 /* FIXME: Set last error*/
107 void TlsSetValue(DWORD index,LPVOID value)
111 /* FIXME: Set last error*/
117 /* FIXME: This is required to work cross-addres space as well */
118 static CRITICAL_SECTION interlocked;
119 static int interlocked_init;
121 static void get_interlocked()
123 if(!interlocked_init)
124 InitializeCriticalSection(&interlocked);
126 EnterCriticalSection(&interlocked);
129 static void release_interlocked()
131 LeaveCriticalSection(&interlocked);
134 /***********************************************************************
135 * InterlockedIncrement
137 LONG InterlockedIncrement(LPLONG lpAddend)
143 release_interlocked();
147 /***********************************************************************
148 * InterlockedDecrement
150 LONG InterlockedDecrement(LPLONG lpAddend)
156 release_interlocked();
160 /***********************************************************************
161 * InterlockedExchange
163 LONG InterlockedExchange(LPLONG target, LONG value)
169 release_interlocked();