diff --git a/lib/ssm/include/ssm.h b/lib/ssm/include/ssm.h index 9e3d9e40..5e59531a 100644 --- a/lib/ssm/include/ssm.h +++ b/lib/ssm/include/ssm.h @@ -68,6 +68,15 @@ See [the detailed documentation](@ref all) #define SSM_ACT_FREE(ptr, size) free(ptr) #endif +/** Underlying exception handler; can be overridden by each platform + * + * ssm_throw is declared as a weak symbol, meaning it will be left a null + * pointer if the linker does not find a definition for this symbol in any + * object file. + */ +void ssm_throw(int reason, const char *file, int line, const char *func) + __attribute__((weak)); + /** Invoked when a process must terminate, e.g., when memory or queue space is * exhausted. Not expected to return. * @@ -76,13 +85,12 @@ See [the detailed documentation](@ref all) * overridden by defining ssm_throw. */ #define SSM_THROW(reason) \ - ssm_throw ? \ - ssm_throw(reason, __FILE__, __LINE__, __func__) : \ - exit(reason) - -/** Underlying crash handler; can be overriden. */ -void ssm_throw(int reason, const char *file, int line, const char *func) - __attribute__((weak)); + do \ + if (ssm_throw) \ + ssm_throw(reason, __FILE__, __LINE__, __func__); \ + else \ + for(;;); \ + while (0) /** Error codes, indicating reason for failure. * diff --git a/lib/ssm/src/ssm-scheduler.c b/lib/ssm/src/ssm-scheduler.c index 9ae6c160..35fb3b53 100644 --- a/lib/ssm/src/ssm-scheduler.c +++ b/lib/ssm/src/ssm-scheduler.c @@ -297,14 +297,14 @@ void ssm_unschedule(ssm_sv_t *var) q_idx_t hole = find_queued_event(var); var->later_time = SSM_NEVER; ssm_sv_t *moved_var = event_queue[event_queue_len--]; - if (hole < SSM_QUEUE_HEAD + event_queue_len) { - // Percolate if removal led to hole in the queue. + if (hole < SSM_QUEUE_HEAD + event_queue_len) + // Percolate only if removal led to a hole in the queue; no need to do + // this if we happened to remove the last element of the queue. if (hole == SSM_QUEUE_HEAD || event_queue[hole >> 1]->later_time < moved_var->later_time) event_queue_percolate_down(hole, moved_var); else event_queue_percolate_up(hole, moved_var); - } } }