@@ -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
110114static unsigned __stdcall
115+ #endif
111116bootstrap (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