From 3d96b0ed95e14dfe1666aac8848e08ce4247ec4e Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Tue, 17 Mar 2020 11:52:01 -0400 Subject: [PATCH] chore: namespace and comment softint stuff --- runtime/include/softint.h | 25 +++++++++++++++++++++---- runtime/src/runtime.c | 2 +- runtime/src/softint.c | 22 +++++++++++----------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/runtime/include/softint.h b/runtime/include/softint.h index c730a22..1e72cac 100644 --- a/runtime/include/softint.h +++ b/runtime/include/softint.h @@ -9,7 +9,7 @@ * Externs ***************************************/ -extern __thread volatile sig_atomic_t softint_off; +extern __thread volatile sig_atomic_t softint__is_disabled; /*************************************** * Public Static Inlines @@ -18,22 +18,34 @@ extern __thread volatile sig_atomic_t softint_off; static inline void softint__disable(void) { - while (__sync_bool_compare_and_swap(&softint_off, 0, 1) == false) + while (__sync_bool_compare_and_swap(&softint__is_disabled, 0, 1) == false) ; } + +/** + * Enables signals + */ static inline void softint__enable(void) { - if (__sync_bool_compare_and_swap(&softint_off, 1, 0) == false) assert(0); + if (__sync_bool_compare_and_swap(&softint__is_disabled, 1, 0) == false) assert(0); } +/** + * @returns boolean if signals are enabled + */ static inline int softint__is_enabled(void) { - return (softint_off == 0); + return (softint__is_disabled == 0); } +/** + * Blocks a signal on the current thread + * @param signal - the signal you want to block + * @return 0 on success. Exits program otherwise + **/ static inline int softint__mask(int signal) { @@ -54,6 +66,11 @@ softint__mask(int signal) return 0; } +/** + * Unblocks a signal on the current thread + * @param signal - the signal you want to block + * @return 0 on success. Exits program otherwise + **/ static inline int softint__unmask(int signal) { diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index 179534c..cb9bf5f 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -413,7 +413,7 @@ worker_thread_main(void *return_code) ps_list_head_init(&local_run_queue); ps_list_head_init(&local_completion_queue); - softint_off = 0; + softint__is_disabled = 0; next_context = NULL; #ifndef PREEMPT_DISABLE softint__unmask(SIGALRM); diff --git a/runtime/src/softint.c b/runtime/src/softint.c index d4d2bd5..8e84ec8 100644 --- a/runtime/src/softint.c +++ b/runtime/src/softint.c @@ -18,15 +18,15 @@ * Process Globals ***************************************/ -static const int softints[] = { SIGALRM, SIGUSR1 }; +static const int softint__supported_signals[] = { SIGALRM, SIGUSR1 }; /*************************************** * Thread Globals ***************************************/ -__thread static volatile sig_atomic_t SIGALRM_count = 0; -__thread static volatile sig_atomic_t SIGUSR_count = 0; -__thread volatile sig_atomic_t softint_off = 0; +__thread static volatile sig_atomic_t softint__SIGALRM_count = 0; +__thread static volatile sig_atomic_t softint__SIGUSR_count = 0; +__thread volatile sig_atomic_t softint__is_disabled = 0; /*************************************** * Externs @@ -75,10 +75,10 @@ softint__handle_signals(int signal_type, siginfo_t *signal_info, void *user_cont } else { assert(signal_info->si_code == SI_TKILL); } - // debuglog("alrm:%d\n", SIGALRM_count); + // debuglog("alrm:%d\n", softint__SIGALRM_count); - SIGALRM_count++; - // softints per-core.. + softint__SIGALRM_count++; + // softint__supported_signals per-core.. if (curr && curr->state == RETURNED) return; if (next_context) return; if (!softint__is_enabled()) return; @@ -92,9 +92,9 @@ softint__handle_signals(int signal_type, siginfo_t *signal_info, void *user_cont /* we set current before calling pthread_kill! */ assert(next_context && (&curr->ctxt == next_context)); assert(signal_info->si_code == SI_TKILL); - // debuglog("usr1:%d\n", SIGUSR_count); + // debuglog("usr1:%d\n", softint__SIGUSR_count); - SIGUSR_count++; + softint__SIGUSR_count++; // do not save current sandbox.. it is in co-operative switch.. // pick the next from "next_context".. // assert its "sp" to be zero in regs.. @@ -205,8 +205,8 @@ softint__initialize(void) signal_action.sa_sigaction = softint__handle_signals; signal_action.sa_flags = SA_SIGINFO | SA_RESTART; - for (int i = 0; i < (sizeof(softints) / sizeof(softints[0])); i++) { - int return_code = sigaction(softints[i], &signal_action, NULL); + for (int i = 0; i < (sizeof(softint__supported_signals) / sizeof(softint__supported_signals[0])); i++) { + int return_code = sigaction(softint__supported_signals[i], &signal_action, NULL); if (return_code) { perror("sigaction"); exit(1);