[Python-checkins] r68542 - in python/trunk: Misc/NEWS Python/thread.c Python/thread_nt.h

martin.v.loewis python-checkins at python.org
Mon Jan 12 09:11:24 CET 2009


Author: martin.v.loewis
Date: Mon Jan 12 09:11:24 2009
New Revision: 68542

Log:
Issue #4893: Use NT threading on CE.


Modified:
   python/trunk/Misc/NEWS
   python/trunk/Python/thread.c
   python/trunk/Python/thread_nt.h

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Mon Jan 12 09:11:24 2009
@@ -12,6 +12,8 @@
 Core and Builtins
 -----------------
 
+- Issue #4893: Use NT threading on CE.
+
 - Issue #4915: Port sysmodule to Windows CE.
 
 - Issue #4074: Change the criteria for doing a full garbage collection (i.e.

Modified: python/trunk/Python/thread.c
==============================================================================
--- python/trunk/Python/thread.c	(original)
+++ python/trunk/Python/thread.c	Mon Jan 12 09:11:24 2009
@@ -137,10 +137,6 @@
 #include "thread_beos.h"
 #endif
 
-#ifdef WINCE_THREADS
-#include "thread_wince.h"
-#endif
-
 #ifdef PLAN9_THREADS
 #include "thread_plan9.h"
 #endif

Modified: python/trunk/Python/thread_nt.h
==============================================================================
--- python/trunk/Python/thread_nt.h	(original)
+++ python/trunk/Python/thread_nt.h	Mon Jan 12 09:11:24 2009
@@ -106,8 +106,13 @@
 	void *arg;
 } callobj;
 
-/* thunker to call a __cdecl function instead of a __stdcall */
+/* thunker to call adapt between the function type used by the system's
+thread start function and the internally used one. */
+#if defined(MS_WINCE)
+static DWORD WINAPI
+#else
 static unsigned __stdcall
+#endif
 bootstrap(void *call)
 {
 	callobj *obj = (callobj*)call;
@@ -135,24 +140,38 @@
 		return -1;
 	obj->func = func;
 	obj->arg = arg;
+#if defined(MS_WINCE)
+	hThread = CreateThread(NULL,
+	                       Py_SAFE_DOWNCAST(_pythread_stacksize, Py_ssize_t, SIZE_T),
+	                       bootstrap, obj, 0, &threadID);
+#else
 	hThread = (HANDLE)_beginthreadex(0,
 			  Py_SAFE_DOWNCAST(_pythread_stacksize,
 					   Py_ssize_t, unsigned int),
 			  bootstrap, obj,
 			  0, &threadID);
+#endif
 	if (hThread == 0) {
+#if defined(MS_WINCE)
+		/* Save error in variable, to prevent PyThread_get_thread_ident
+		   from clobbering it. */
+		unsigned e = GetLastError();
+		dprintf(("%ld: PyThread_start_new_thread failed, win32 error code %u\n",
+		         PyThread_get_thread_ident(), e));
+#else
 		/* I've seen errno == EAGAIN here, which means "there are
 		 * too many threads".
 		 */
+		int e = errno;
 		dprintf(("%ld: PyThread_start_new_thread failed, errno %d\n",
-		         PyThread_get_thread_ident(), errno));
+		         PyThread_get_thread_ident(), e));
+#endif
 		threadID = (unsigned)-1;
 		HeapFree(GetProcessHeap(), 0, obj);
 	}
 	else {
 		dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n",
 		         PyThread_get_thread_ident(), (void*)hThread));
-		/* wait for thread to initialize, so we can get its id */
 		CloseHandle(hThread);
 	}
 	return (long) threadID;
@@ -177,7 +196,11 @@
 	dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident()));
 	if (!initialized)
 		exit(0);
+#if defined(MS_WINCE)
+	ExitThread(0);
+#else
 	_endthreadex(0);
+#endif
 }
 
 #ifndef NO_EXIT_PROG


More information about the Python-checkins mailing list