--- /dev/null
+#ifndef REGTEST\r
+#include <threads.h>\r
+#include <windows.h>\r
+\r
+extern void _PDCLIB_w32errno( void );\r
+int mtx_unlock(mtx_t *mtx)\r
+{\r
+ if(mtx->_NestCount) {\r
+ mtx->_NestCount--;\r
+ return thrd_success;\r
+ }\r
+\r
+ mtx->_ThreadId = 0;\r
+\r
+ DWORD res = InterlockedDecrement(&mtx->_State);\r
+ if(res == (DWORD) -1) {\r
+ // We reset the state to -1; success!\r
+ return thrd_success;\r
+ }\r
+\r
+ DWORD rv = SetEvent(mtx->_WaitEvHandle);\r
+ if(rv == 0) {\r
+ _PDCLIB_w32errno();\r
+ return thrd_error;\r
+ }\r
+\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