2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis
17 /***********************************************************************
18 * GetCurrentThreadId (KERNEL32.201)
21 DWORD
GetCurrentThreadId(void)
23 /* Windows 95 returns the address of the thread database (sorta) */
24 return MAKELONG(GetCurrentTask(), 0);
27 /***********************************************************************
28 * GetThreadContext (KERNEL32.294)
30 BOOL
GetThreadContext(HANDLE32 hThread
, void *lpContext
)
34 /***********************************************************************
35 * GetCurrentThread (KERNEL32.200)
37 HANDLE32
GetCurrentThread(void)
39 return 0xFFFFFFFE; /* that's -2 */
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 void ReinitializeCriticalSection(CRITICAL_SECTION
*lpCrit
) {
75 void MakeCriticalSectionGlobal(CRITICAL_SECTION
*lpCrit
) {
79 /***********************************************************************
80 * Tls is available only for the single thread
81 * (BTW: TLS means Thread Local Storage)
84 static int TlsCount
=0;
90 Tls
=xmalloc(sizeof(LPVOID
));
91 /* Tls needs to be zero initialized */
95 Tls
=xrealloc(Tls
,sizeof(LPVOID
)*(++TlsCount
));
100 void TlsFree(DWORD index
)
102 /*FIXME: should remember that it has been freed */
106 LPVOID
TlsGetValue(DWORD index
)
110 /* FIXME: Set last error*/
116 BOOL32
TlsSetValue(DWORD index
,LPVOID value
)
120 /* FIXME: Set last error*/
127 /* FIXME: This is required to work cross-addres space as well */
128 static CRITICAL_SECTION interlocked
;
129 static int interlocked_init
;
131 static void get_interlocked()
133 if(!interlocked_init
)
134 InitializeCriticalSection(&interlocked
);
136 EnterCriticalSection(&interlocked
);
139 static void release_interlocked()
141 LeaveCriticalSection(&interlocked
);
144 /***********************************************************************
145 * InterlockedIncrement
147 LONG
InterlockedIncrement(LPLONG lpAddend
)
153 release_interlocked();
157 /***********************************************************************
158 * InterlockedDecrement
160 LONG
InterlockedDecrement(LPLONG lpAddend
)
166 release_interlocked();
170 /***********************************************************************
171 * InterlockedExchange
173 LONG
InterlockedExchange(LPLONG target
, LONG value
)
179 release_interlocked();