Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream ssm #85

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions lib/ssm/include/ssm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down
6 changes: 3 additions & 3 deletions lib/ssm/src/ssm-scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down