Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3422fa

Browse files
committed
Issue python#4893: Use NT threading on CE.
1 parent 1b3bef2 commit e3422fa

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ What's New in Python 2.7 alpha 1
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #4893: Use NT threading on CE.
16+
1517
- Issue #4915: Port sysmodule to Windows CE.
1618

1719
- Issue #4074: Change the criteria for doing a full garbage collection (i.e.

Python/thread.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ static size_t _pythread_stacksize = 0;
137137
#include "thread_beos.h"
138138
#endif
139139

140-
#ifdef WINCE_THREADS
141-
#include "thread_wince.h"
142-
#endif
143-
144140
#ifdef PLAN9_THREADS
145141
#include "thread_plan9.h"
146142
#endif

Python/thread_nt.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,13 @@ typedef struct {
106106
void *arg;
107107
} callobj;
108108

109-
/* thunker to call a __cdecl function instead of a __stdcall */
109+
/* thunker to call adapt between the function type used by the system's
110+
thread start function and the internally used one. */
111+
#if defined(MS_WINCE)
112+
static DWORD WINAPI
113+
#else
110114
static unsigned __stdcall
115+
#endif
111116
bootstrap(void *call)
112117
{
113118
callobj *obj = (callobj*)call;
@@ -135,24 +140,38 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
135140
return -1;
136141
obj->func = func;
137142
obj->arg = arg;
143+
#if defined(MS_WINCE)
144+
hThread = CreateThread(NULL,
145+
Py_SAFE_DOWNCAST(_pythread_stacksize, Py_ssize_t, SIZE_T),
146+
bootstrap, obj, 0, &threadID);
147+
#else
138148
hThread = (HANDLE)_beginthreadex(0,
139149
Py_SAFE_DOWNCAST(_pythread_stacksize,
140150
Py_ssize_t, unsigned int),
141151
bootstrap, obj,
142152
0, &threadID);
153+
#endif
143154
if (hThread == 0) {
155+
#if defined(MS_WINCE)
156+
/* Save error in variable, to prevent PyThread_get_thread_ident
157+
from clobbering it. */
158+
unsigned e = GetLastError();
159+
dprintf(("%ld: PyThread_start_new_thread failed, win32 error code %u\n",
160+
PyThread_get_thread_ident(), e));
161+
#else
144162
/* I've seen errno == EAGAIN here, which means "there are
145163
* too many threads".
146164
*/
165+
int e = errno;
147166
dprintf(("%ld: PyThread_start_new_thread failed, errno %d\n",
148-
PyThread_get_thread_ident(), errno));
167+
PyThread_get_thread_ident(), e));
168+
#endif
149169
threadID = (unsigned)-1;
150170
HeapFree(GetProcessHeap(), 0, obj);
151171
}
152172
else {
153173
dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n",
154174
PyThread_get_thread_ident(), (void*)hThread));
155-
/* wait for thread to initialize, so we can get its id */
156175
CloseHandle(hThread);
157176
}
158177
return (long) threadID;
@@ -177,7 +196,11 @@ PyThread_exit_thread(void)
177196
dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident()));
178197
if (!initialized)
179198
exit(0);
199+
#if defined(MS_WINCE)
200+
ExitThread(0);
201+
#else
180202
_endthreadex(0);
203+
#endif
181204
}
182205

183206
#ifndef NO_EXIT_PROG

0 commit comments

Comments
 (0)