X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fthread.c;h=9871f9fbf6f8edca3831ebf543b99a6e946375a8;hb=3106aee96a20d1a76a114e504bc2931f8196cace;hp=a99056fa791f1e234824ac517921c12829bfc5d5;hpb=25fe91bf63fd473d9316675b0e0ca9be0079e9eb;p=sbcl.git diff --git a/src/runtime/thread.c b/src/runtime/thread.c index a99056f..9871f9f 100644 --- a/src/runtime/thread.c +++ b/src/runtime/thread.c @@ -25,6 +25,12 @@ #include #endif +#ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER +#include +#include +#include +#endif + #include "runtime.h" #include "validate.h" /* for CONTROL_STACK_SIZE etc */ #include "alloc.h" @@ -49,6 +55,7 @@ #if defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_SB_THREAD) #define QUEUE_FREEABLE_THREAD_STACKS +#define LOCK_CREATE_THREAD #endif #ifdef LISP_FEATURE_FREEBSD @@ -143,6 +150,7 @@ initial_thread_trampoline(struct thread *th) #ifdef QUEUE_FREEABLE_THREAD_STACKS +static void queue_freeable_thread_stack(struct thread *thread_to_be_cleaned_up) { if (thread_to_be_cleaned_up) { @@ -312,6 +320,17 @@ new_thread_trampoline(struct thread *th) os_invalidate((os_vm_address_t)th->interrupt_data, (sizeof (struct interrupt_data))); +#ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER + FSHOW((stderr, "Deallocating mach port %x\n", THREAD_STRUCT_TO_EXCEPTION_PORT(th))); + mach_port_move_member(mach_task_self(), + THREAD_STRUCT_TO_EXCEPTION_PORT(th), + MACH_PORT_NULL); + mach_port_deallocate(mach_task_self(), + THREAD_STRUCT_TO_EXCEPTION_PORT(th)); + mach_port_destroy(mach_task_self(), + THREAD_STRUCT_TO_EXCEPTION_PORT(th)); +#endif + #ifdef QUEUE_FREEABLE_THREAD_STACKS queue_freeable_thread_stack(th); #elif defined(CREATE_CLEANUP_THREAD) @@ -350,6 +369,10 @@ create_thread_struct(lispobj initial_function) { int i; #endif +#ifdef CREATE_CLEANUP_THREAD + /* Give a chance for cleanup threads to run. */ + sched_yield(); +#endif /* may as well allocate all the spaces at once: it saves us from * having to decide what to do if only some of the allocations * succeed */ @@ -457,9 +480,20 @@ create_thread_struct(lispobj initial_function) { return th; } +#ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER +mach_port_t setup_mach_exception_handling_thread(); +kern_return_t mach_thread_init(mach_port_t thread_exception_port); + +#endif + void create_initial_thread(lispobj initial_function) { struct thread *th=create_thread_struct(initial_function); if(th) { +#ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER + kern_return_t ret; + + setup_mach_exception_handling_thread(); +#endif initial_thread_trampoline(th); /* no return */ } else lose("can't create initial thread\n"); } @@ -516,6 +550,7 @@ boolean create_os_thread(struct thread *th,os_thread_t *kid_tid) } r=0; } + #ifdef QUEUE_FREEABLE_THREAD_STACKS free_freeable_stacks(); #endif