2 /* This code implemented by Mark Hammond (MHammond@skippinet.com.au) */
8 long PyThread_get_thread_ident(void);
11 * Change all headers to pure ANSI as no one will use K&R style on an
16 * Initialization of the C package, should not be needed.
18 static void PyThread__init_thread(void)
25 long PyThread_start_new_thread(void (*func
)(void *), void *arg
)
30 dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident()));
32 PyThread_init_thread();
34 rv
= _beginthread(func
, 0, arg
); /* use default stack size */
38 dprintf(("%ld: PyThread_start_new_thread succeeded:\n", PyThread_get_thread_ident()));
45 * Return the thread Id instead of an handle. The Id is said to uniquely identify the
46 * thread in the system
48 long PyThread_get_thread_ident(void)
51 PyThread_init_thread();
53 return GetCurrentThreadId();
56 void PyThread_exit_thread(void)
58 dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident()));
65 * Lock support. It has to be implemented using Mutexes, as
66 * CE doesnt support semaphores. Therefore we use some hacks to
67 * simulate the non reentrant requirements of Python locks
69 PyThread_type_lock
PyThread_allocate_lock(void)
73 dprintf(("PyThread_allocate_lock called\n"));
75 PyThread_init_thread();
77 aLock
= CreateEvent(NULL
, /* Security attributes */
79 1, /* Is initially signalled */
80 NULL
); /* Name of event */
82 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock
));
84 return (PyThread_type_lock
) aLock
;
87 void PyThread_free_lock(PyThread_type_lock aLock
)
89 dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock
));
95 * Return 1 on success if the lock was acquired
97 * and 0 if the lock was not acquired. This means a 0 is returned
98 * if the lock has already been acquired by this thread!
100 int PyThread_acquire_lock(PyThread_type_lock aLock
, int waitflag
)
105 dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(),aLock
, waitflag
));
108 waitResult
= WaitForSingleObject(aLock
, (waitflag
? INFINITE
: 0));
110 /* To aid in debugging, we regularly wake up. This allows us to
111 break into the debugger */
113 waitResult
= WaitForSingleObject(aLock
, waitflag
? 3000 : 0);
114 if (waitflag
==0 || (waitflag
&& waitResult
== WAIT_OBJECT_0
))
119 if (waitResult
!= WAIT_OBJECT_0
) {
120 success
= 0; /* We failed */
123 dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", PyThread_get_thread_ident(),aLock
, waitflag
, success
));
128 void PyThread_release_lock(PyThread_type_lock aLock
)
130 dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock
));
132 if (!SetEvent(aLock
))
133 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock
, GetLastError()));