From 273d754ed28c2efb3c91395a05d0a6f36e98bb72 Mon Sep 17 00:00:00 2001 From: "R. Matthew Emerson" Date: Tue, 23 Apr 2024 16:18:09 -0700 Subject: [PATCH 1/2] Delete some dead code pertaining to cooperative threads --- lisp-kernel/imports.s | 2 +- lisp-kernel/thread_manager.c | 55 ++++-------------------------------- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/lisp-kernel/imports.s b/lisp-kernel/imports.s index 48ea77b37..01070869d 100644 --- a/lisp-kernel/imports.s +++ b/lisp-kernel/imports.s @@ -57,7 +57,7 @@ import_ptrs_start: defimport(lisp_egc_control) defimport(lisp_bug) defimport(xNewThread) - defimport(cooperative_thread_startup) + defimport(do_nothing) defimport(xDisposeThread) defimport(xThreadCurrentStackSpace) defimport(usage_exit) diff --git a/lisp-kernel/thread_manager.c b/lisp-kernel/thread_manager.c index abcfb80fc..7703ae492 100644 --- a/lisp-kernel/thread_manager.c +++ b/lisp-kernel/thread_manager.c @@ -1689,56 +1689,6 @@ lisp_thread_entry(void *param) #endif } -typedef -short (*suspendf)(); - - -void -suspend_current_cooperative_thread() -{ - static suspendf cooperative_suspend = NULL; - void *xFindSymbol(void*,char*); - - if (cooperative_suspend == NULL) { - cooperative_suspend = (suspendf)xFindSymbol(NULL, "SetThreadState"); - } - if (cooperative_suspend) { - cooperative_suspend(1 /* kCurrentThreadID */, - 1 /* kStoppedThreadState */, - 0 /* kAnyThreadID */); - } -} - -void * -cooperative_thread_startup(void *arg) -{ - - TCR *tcr = get_tcr(0); - LispObj *start_vsp; - - if (!tcr) { - return NULL; - } -#ifndef WINDOWS - pthread_cleanup_push(tcr_cleanup,(void *)tcr); -#endif - SET_TCR_FLAG(tcr,TCR_FLAG_BIT_AWAITING_PRESET); - start_vsp = tcr->save_vsp; - do { - SEM_RAISE(TCR_AUX(tcr)->reset_completion); - suspend_current_cooperative_thread(); - - start_lisp(tcr, 0); - tcr->save_vsp = start_vsp; - } while (tcr->flags & (1< Date: Tue, 23 Apr 2024 16:18:59 -0700 Subject: [PATCH 2/2] Address some lisp kernel compiler warnings --- lisp-kernel/thread_manager.c | 15 +++++++++------ lisp-kernel/x86-exceptions.c | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lisp-kernel/thread_manager.c b/lisp-kernel/thread_manager.c index 7703ae492..93ce3832a 100644 --- a/lisp-kernel/thread_manager.c +++ b/lisp-kernel/thread_manager.c @@ -1368,9 +1368,11 @@ shutdown_thread_tcr(void *arg) if (tcr->flags & (1<address; - + int (*foreign_thread_control)(int) = (int (*)(int))callback_ptr; + tsd_set(lisp_global(TCR_KEY), TCR_TO_TSD(tcr)); - ((void (*)())ptr_from_lispobj(callback_ptr))(1); + foreign_thread_control(1); + //((void (*)(int))ptr_from_lispobj(callback_ptr))(1); tsd_set(lisp_global(TCR_KEY), NULL); } #ifdef DARWIN @@ -1847,6 +1849,7 @@ get_tcr(Boolean create) if ((current == NULL) && create) { LispObj callback_macptr = nrs_FOREIGN_THREAD_CONTROL.vcell, callback_ptr = ((macptr *)ptr_from_lispobj(untag(callback_macptr)))->address; + int (*foreign_thread_control)(int) = (int (*)(int))callback_ptr; int i, nbindwords = 0; extern natural initial_stack_size; @@ -1877,13 +1880,13 @@ get_tcr(Boolean create) *(--current->save_vsp) = 0; current->vs_area->active -= node_size; } - nbindwords = ((int (*)())ptr_from_lispobj(callback_ptr))(-1); + nbindwords = foreign_thread_control(-1); for (i = 0; i < nbindwords; i++) { *(--current->save_vsp) = 0; current->vs_area->active -= node_size; } TCR_AUX(current)->shutdown_count = 1; - ((void (*)())ptr_from_lispobj(callback_ptr))(0); + foreign_thread_control(0); } @@ -2047,7 +2050,7 @@ create_thread_context_frame(mach_port_t, natural *, siginfo_t *, TCR*, native_th Boolean mach_suspend_tcr(TCR *tcr) { - thread_act_t thread = (thread_act_t)(tcr->native_thread_id); + mach_port_t thread = (mach_port_t)((intptr_t)tcr->native_thread_id); kern_return_t kret = thread_suspend(thread); if (kret == 0) { @@ -2209,7 +2212,7 @@ resume_tcr(TCR *tcr) Boolean mach_resume_tcr(TCR *tcr) { ExceptionInformation *xp = tcr->suspend_context; - mach_port_t thread = (mach_port_t)(tcr->native_thread_id); + mach_port_t thread = (mach_port_t)((intptr_t)(tcr->native_thread_id)); #if WORD_SIZE == 64 MCONTEXT_T mc = UC_MCONTEXT(xp); #else diff --git a/lisp-kernel/x86-exceptions.c b/lisp-kernel/x86-exceptions.c index 75dea85eb..6eeee55a2 100644 --- a/lisp-kernel/x86-exceptions.c +++ b/lisp-kernel/x86-exceptions.c @@ -678,7 +678,6 @@ handle_alloc_trap(ExceptionInformation *xp, TCR *tcr, Boolean *notify) return true; } - int callback_to_lisp (TCR * tcr, LispObj callback_macptr, ExceptionInformation *xp, natural arg1, natural arg2, natural arg3, natural arg4, natural arg5) @@ -712,8 +711,12 @@ callback_to_lisp (TCR * tcr, LispObj callback_macptr, ExceptionInformation *xp, pointers (and at least should have called prepare_for_callback()). */ callback_ptr = ((macptr *)ptr_from_lispobj(untag(callback_macptr)))->address; + typedef int (*callback_fn_type)(ExceptionInformation *, natural, natural, + natural, natural, natural); + callback_fn_type callback_fn = (callback_fn_type)callback_ptr; + UNLOCK(lisp_global(EXCEPTION_LOCK), tcr); - delta = ((int (*)())callback_ptr) (xp, arg1, arg2, arg3, arg4, arg5); + delta = callback_fn(xp, arg1, arg2, arg3, arg4, arg5); LOCK(lisp_global(EXCEPTION_LOCK), tcr); #ifdef X8632