246 |
_ILPrivateThreadDestroy(thread, 0); |
_ILPrivateThreadDestroy(thread, 0); |
247 |
} |
} |
248 |
|
|
249 |
|
void *ILThreadRunSelf(void *(* thread_func)(void *), void *arg) |
250 |
|
{ |
251 |
|
ILThread *thread_self; |
252 |
|
void *result; |
253 |
|
|
254 |
|
/* Create a new thread object and populate it */ |
255 |
|
thread_self = (ILThread *)ILCalloc(1, sizeof(ILThread)); |
256 |
|
if(!thread_self) |
257 |
|
{ |
258 |
|
return 0; |
259 |
|
} |
260 |
|
|
261 |
|
_ILMutexCreate(&(thread_self->lock)); |
262 |
|
thread_self->state = IL_TS_UNSTARTED; |
263 |
|
thread_self->resumeRequested = 0; |
264 |
|
thread_self->suspendRequested = 0; |
265 |
|
thread_self->numLocksHeld = 0; |
266 |
|
thread_self->firstCleanupEntry = 0; |
267 |
|
thread_self->lastCleanupEntry = 0; |
268 |
|
thread_self->monitor = ILWaitMonitorCreate(); |
269 |
|
_ILSemaphoreCreate(&(thread_self->resumeAck)); |
270 |
|
_ILSemaphoreCreate(&(thread_self->suspendAck)); |
271 |
|
thread_self->startFunc = 0; |
272 |
|
thread_self->userObject = 0; |
273 |
|
thread_self->startArg = 0; |
274 |
|
_ILWakeupCreate(&(thread_self->wakeup)); |
275 |
|
_ILWakeupQueueCreate(&(thread_self->joinQueue)); |
276 |
|
thread_self->handle = 0; |
277 |
|
thread_self->destroyOnExit = 0; |
278 |
|
#ifdef IL_INTERRUPT_SUPPORTS |
279 |
|
thread_self->interruptHandler = 0; |
280 |
|
#endif |
281 |
|
|
282 |
|
/* Initialize the handle and the identifier */ |
283 |
|
_ILThreadInitHandleSelf(thread_self); |
284 |
|
|
285 |
|
/* Set the thread object for the thread */ |
286 |
|
_ILThreadSetSelf(thread_self); |
287 |
|
|
288 |
|
#ifdef HAVE_LIBGC |
289 |
|
result = GC_run_thread(thread_func, arg); |
290 |
|
#else |
291 |
|
result = thread_func(arg); |
292 |
|
#endif |
293 |
|
|
294 |
|
_ILThreadRunAndFreeCleanups(thread_self); |
295 |
|
|
296 |
|
/* and now destroy the ILThread instance. */ |
297 |
|
ILWaitHandleClose(thread_self->monitor); |
298 |
|
_ILMutexDestroy(&(thread_self->lock)); |
299 |
|
_ILSemaphoreDestroy(&(thread_self->suspendAck)); |
300 |
|
_ILSemaphoreDestroy(&(thread_self->resumeAck)); |
301 |
|
_ILWakeupQueueDestroy(&(thread_self->joinQueue)); |
302 |
|
|
303 |
|
_ILThreadSetSelf(0); |
304 |
|
/* Release the handle */ |
305 |
|
_ILThreadDestroy(thread_self); |
306 |
|
|
307 |
|
ILFree(thread_self); |
308 |
|
|
309 |
|
return result; |
310 |
|
} |
311 |
|
|
312 |
void _ILThreadRun(ILThread *thread) |
void _ILThreadRun(ILThread *thread) |
313 |
{ |
{ |
314 |
/* When a thread starts, it blocks until the ILThreadStart function |
/* When a thread starts, it blocks until the ILThreadStart function |