chore: namespace and comment softint stuff

main
Sean McBride 5 years ago
parent d6c31f6728
commit 3d96b0ed95

@ -9,7 +9,7 @@
* Externs * Externs
***************************************/ ***************************************/
extern __thread volatile sig_atomic_t softint_off; extern __thread volatile sig_atomic_t softint__is_disabled;
/*************************************** /***************************************
* Public Static Inlines * Public Static Inlines
@ -18,22 +18,34 @@ extern __thread volatile sig_atomic_t softint_off;
static inline void static inline void
softint__disable(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 static inline void
softint__enable(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 static inline int
softint__is_enabled(void) 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 static inline int
softint__mask(int signal) softint__mask(int signal)
{ {
@ -54,6 +66,11 @@ softint__mask(int signal)
return 0; 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 static inline int
softint__unmask(int signal) softint__unmask(int signal)
{ {

@ -413,7 +413,7 @@ worker_thread_main(void *return_code)
ps_list_head_init(&local_run_queue); ps_list_head_init(&local_run_queue);
ps_list_head_init(&local_completion_queue); ps_list_head_init(&local_completion_queue);
softint_off = 0; softint__is_disabled = 0;
next_context = NULL; next_context = NULL;
#ifndef PREEMPT_DISABLE #ifndef PREEMPT_DISABLE
softint__unmask(SIGALRM); softint__unmask(SIGALRM);

@ -18,15 +18,15 @@
* Process Globals * Process Globals
***************************************/ ***************************************/
static const int softints[] = { SIGALRM, SIGUSR1 }; static const int softint__supported_signals[] = { SIGALRM, SIGUSR1 };
/*************************************** /***************************************
* Thread Globals * Thread Globals
***************************************/ ***************************************/
__thread static volatile sig_atomic_t SIGALRM_count = 0; __thread static volatile sig_atomic_t softint__SIGALRM_count = 0;
__thread static volatile sig_atomic_t SIGUSR_count = 0; __thread static volatile sig_atomic_t softint__SIGUSR_count = 0;
__thread volatile sig_atomic_t softint_off = 0; __thread volatile sig_atomic_t softint__is_disabled = 0;
/*************************************** /***************************************
* Externs * Externs
@ -75,10 +75,10 @@ softint__handle_signals(int signal_type, siginfo_t *signal_info, void *user_cont
} else { } else {
assert(signal_info->si_code == SI_TKILL); assert(signal_info->si_code == SI_TKILL);
} }
// debuglog("alrm:%d\n", SIGALRM_count); // debuglog("alrm:%d\n", softint__SIGALRM_count);
SIGALRM_count++; softint__SIGALRM_count++;
// softints per-core.. // softint__supported_signals per-core..
if (curr && curr->state == RETURNED) return; if (curr && curr->state == RETURNED) return;
if (next_context) return; if (next_context) return;
if (!softint__is_enabled()) 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! */ /* we set current before calling pthread_kill! */
assert(next_context && (&curr->ctxt == next_context)); assert(next_context && (&curr->ctxt == next_context));
assert(signal_info->si_code == SI_TKILL); 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.. // do not save current sandbox.. it is in co-operative switch..
// pick the next from "next_context".. // pick the next from "next_context"..
// assert its "sp" to be zero in regs.. // 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_sigaction = softint__handle_signals;
signal_action.sa_flags = SA_SIGINFO | SA_RESTART; signal_action.sa_flags = SA_SIGINFO | SA_RESTART;
for (int i = 0; i < (sizeof(softints) / sizeof(softints[0])); i++) { for (int i = 0; i < (sizeof(softint__supported_signals) / sizeof(softint__supported_signals[0])); i++) {
int return_code = sigaction(softints[i], &signal_action, NULL); int return_code = sigaction(softint__supported_signals[i], &signal_action, NULL);
if (return_code) { if (return_code) {
perror("sigaction"); perror("sigaction");
exit(1); exit(1);

Loading…
Cancel
Save