]> pd.if.org Git - pdclib/blob - platform/win32/functions/threads/mtx_lock.c
Cosmetic comment fixes.
[pdclib] / platform / win32 / functions / threads / mtx_lock.c
1 #ifndef REGTEST
2 #include <threads.h>
3 #include <windows.h>
4
5 int mtx_lock(mtx_t *mtx)
6 {
7     DWORD myId = GetCurrentThreadId();
8
9     if(mtx->_ThreadId == (long) myId) {
10         mtx->_NestCount++;
11         return thrd_success;
12     }
13
14     for(;;) {
15         LONG prev = InterlockedCompareExchange(&mtx->_ThreadId, myId, 0);
16         if(prev == 0)
17             return thrd_success;
18
19         DWORD rv = WaitForSingleObject(mtx->_WaitEvHandle, INFINITE);
20         if(rv != WAIT_OBJECT_0)
21             return thrd_error;
22     }
23 }
24 #endif
25
26 #ifdef TEST
27 #include "_PDCLIB_test.h"
28
29 int main( void )
30 {
31     return TEST_RESULTS;
32 }
33
34 #endif