--- /dev/null
+#ifndef REGTEST\r
+#include <threads.h>\r
+#include <windows.h>\r
+\r
+int mtx_lock(mtx_t *mtx)\r
+{\r
+ DWORD myId = GetCurrentThreadId();\r
+\r
+ if(mtx->_ThreadId == myId) {\r
+ mtx->_NestCount++;\r
+ return thrd_success;\r
+ }\r
+\r
+ DWORD res = InterlockedIncrement(&mtx->_State);\r
+ if(res == 0) {\r
+ mtx->_ThreadId = myId;\r
+ return thrd_success;\r
+ }\r
+\r
+ // If that increment didn't leave the state == 0, then we have contention\r
+ // -> block on the wait event handle\r
+ DWORD rv = WaitForSingleObject(mtx->_WaitEvHandle, INFINITE);\r
+ if(rv != WAIT_OBJECT_0) \r
+ return thrd_error;\r
+\r
+ // We now own the mutex - so set it up for our use\r
+ mtx->_ThreadId = myId;\r
+ return thrd_success;\r
+}\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+ return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file