2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis
17 /***********************************************************************
18 * GetCurrentThreadId (KERNEL32.200)
21 int GetCurrentThreadId(void)
26 /***********************************************************************
27 * GetThreadContext (KERNEL32.294)
29 BOOL
GetThreadContext(HANDLE hThread
, void *lpContext
)
33 /***********************************************************************
34 * GetCurrentThread (KERNEL32.200)
36 HANDLE
GetCurrentThread(void)
41 /**********************************************************************
42 * Critical Sections are currently ignored
44 void InitializeCriticalSection(CRITICAL_SECTION
*lpCrit
)
46 memset(lpCrit
,0,sizeof(CRITICAL_SECTION
));
49 void EnterCriticalSection(CRITICAL_SECTION
* lpCrit
)
51 if (lpCrit
->LockCount
)
52 fprintf( stderr
, "Error: re-entering critical section %08lx\n",
57 void LeaveCriticalSection(CRITICAL_SECTION
* lpCrit
)
59 if (!lpCrit
->LockCount
)
60 fprintf( stderr
, "Error: leaving critical section %08lx again\n",
65 void DeleteCriticalSection(CRITICAL_SECTION
* lpCrit
)
71 ReinitializeCriticalSection(CRITICAL_SECTION
*lpCrit
) {
75 /***********************************************************************
76 * Tls is available only for the single thread
77 * (BTW: TLS means Thread Local Storage)
80 static int TlsCount
=0;
86 Tls
=xmalloc(sizeof(LPVOID
));
87 /* Tls needs to be zero initialized */
91 Tls
=xrealloc(Tls
,sizeof(LPVOID
)*(++TlsCount
));
96 void TlsFree(DWORD index
)
98 /*FIXME: should remember that it has been freed */
102 LPVOID
TlsGetValue(DWORD index
)
106 /* FIXME: Set last error*/
112 BOOL32
TlsSetValue(DWORD index
,LPVOID value
)
116 /* FIXME: Set last error*/
123 /* FIXME: This is required to work cross-addres space as well */
124 static CRITICAL_SECTION interlocked
;
125 static int interlocked_init
;
127 static void get_interlocked()
129 if(!interlocked_init
)
130 InitializeCriticalSection(&interlocked
);
132 EnterCriticalSection(&interlocked
);
135 static void release_interlocked()
137 LeaveCriticalSection(&interlocked
);
140 /***********************************************************************
141 * InterlockedIncrement
143 LONG
InterlockedIncrement(LPLONG lpAddend
)
149 release_interlocked();
153 /***********************************************************************
154 * InterlockedDecrement
156 LONG
InterlockedDecrement(LPLONG lpAddend
)
162 release_interlocked();
166 /***********************************************************************
167 * InterlockedExchange
169 LONG
InterlockedExchange(LPLONG target
, LONG value
)
175 release_interlocked();