+++ /dev/null
-\r
-/* This code implemented by Mark Hammond (MHammond@skippinet.com.au) */\r
-\r
-#include <windows.h>\r
-#include <limits.h>\r
-#include <pydebug.h>\r
-\r
-long PyThread_get_thread_ident(void);\r
-\r
-/*\r
- * Change all headers to pure ANSI as no one will use K&R style on an\r
- * NT\r
- */\r
-\r
-/*\r
- * Initialization of the C package, should not be needed.\r
- */\r
-static void PyThread__init_thread(void)\r
-{\r
-}\r
-\r
-/*\r
- * Thread support.\r
- */\r
-long PyThread_start_new_thread(void (*func)(void *), void *arg)\r
-{\r
- long rv;\r
- int success = -1;\r
-\r
- dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident()));\r
- if (!initialized)\r
- PyThread_init_thread();\r
-\r
- rv = _beginthread(func, 0, arg); /* use default stack size */\r
-\r
- if (rv != -1) {\r
- success = 0;\r
- dprintf(("%ld: PyThread_start_new_thread succeeded:\n", PyThread_get_thread_ident()));\r
- }\r
-\r
- return success;\r
-}\r
-\r
-/*\r
- * Return the thread Id instead of an handle. The Id is said to uniquely identify the\r
- * thread in the system\r
- */\r
-long PyThread_get_thread_ident(void)\r
-{\r
- if (!initialized)\r
- PyThread_init_thread();\r
-\r
- return GetCurrentThreadId();\r
-}\r
-\r
-void PyThread_exit_thread(void)\r
-{\r
- dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident()));\r
- if (!initialized)\r
- exit(0);\r
- _endthread();\r
-}\r
-\r
-/*\r
- * Lock support. It has to be implemented using Mutexes, as\r
- * CE doesnt support semaphores. Therefore we use some hacks to\r
- * simulate the non reentrant requirements of Python locks\r
- */\r
-PyThread_type_lock PyThread_allocate_lock(void)\r
-{\r
- HANDLE aLock;\r
-\r
- dprintf(("PyThread_allocate_lock called\n"));\r
- if (!initialized)\r
- PyThread_init_thread();\r
-\r
- aLock = CreateEvent(NULL, /* Security attributes */\r
- 0, /* Manual-Reset */\r
- 1, /* Is initially signalled */\r
- NULL); /* Name of event */\r
-\r
- dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock));\r
-\r
- return (PyThread_type_lock) aLock;\r
-}\r
-\r
-void PyThread_free_lock(PyThread_type_lock aLock)\r
-{\r
- dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock));\r
-\r
- CloseHandle(aLock);\r
-}\r
-\r
-/*\r
- * Return 1 on success if the lock was acquired\r
- *\r
- * and 0 if the lock was not acquired. This means a 0 is returned\r
- * if the lock has already been acquired by this thread!\r
- */\r
-int PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag)\r
-{\r
- int success = 1;\r
- DWORD waitResult;\r
-\r
- dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(),aLock, waitflag));\r
-\r
-#ifndef DEBUG\r
- waitResult = WaitForSingleObject(aLock, (waitflag ? INFINITE : 0));\r
-#else\r
- /* To aid in debugging, we regularly wake up. This allows us to\r
- break into the debugger */\r
- while (TRUE) {\r
- waitResult = WaitForSingleObject(aLock, waitflag ? 3000 : 0);\r
- if (waitflag==0 || (waitflag && waitResult == WAIT_OBJECT_0))\r
- break;\r
- }\r
-#endif\r
-\r
- if (waitResult != WAIT_OBJECT_0) {\r
- success = 0; /* We failed */\r
- }\r
-\r
- dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", PyThread_get_thread_ident(),aLock, waitflag, success));\r
-\r
- return success;\r
-}\r
-\r
-void PyThread_release_lock(PyThread_type_lock aLock)\r
-{\r
- dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock));\r
-\r
- if (!SetEvent(aLock))\r
- dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError()));\r
-}\r
-\r
-\r