ssm
0.0.2
Runtime Library for the Sparse Synchronous Model
|
Scheduled variables are special references to which instantaneous and delayed assignments may be made. More...
Scheduled variables are special references to which instantaneous and delayed assignments may be made.
When such an assignment is made, all sensitive routines (with a lower priority, for instantaneous assignments) are woken and scheduled for execution in that instant. A scheduled assignment is also referred to as an event.
When the last reference to a scheduled variable is dropped, any outstanding scheduled assignments to it will be cancelled. Note, however, at that the current implementation of this is rather costly (linear in the total number of queued events at that time).
Data Structures | |
struct | ssm_sv |
A scheduled variable that supports scheduled updates with triggers. More... | |
Macros | |
#define | ssm_new_sv(v) |
#define | ssm_to_sv(val) container_of((val).heap_ptr, ssm_sv_t, mm) |
Retrieve ssm_sv pointer pointed to by an ssm_value_t. More... | |
#define | ssm_deref(val) (ssm_to_sv(val)->value) |
Read the value of a scheduled variable. More... | |
#define | ssm_assign(var, prio, val) |
Instantaneous assignment to a scheduled variable. More... | |
#define | ssm_later(var, when, val) |
Delayed assignment to a scheduled variable. More... | |
#define | ssm_sensitize(var, trig) ssm_sv_sensitize(ssm_to_sv(var), trig) |
Sensitize a trigger to a scheduled variable. More... | |
#define | ssm_desensitize(trig) ssm_sv_desensitize(trig) |
Desensitize a trigger. More... | |
Typedefs | |
typedef struct ssm_sv | ssm_sv_t |
A scheduled variable that supports scheduled updates with triggers. More... | |
Functions | |
void | ssm_update (ssm_sv_t *sv) |
Perform a (delayed) update on a variable. More... | |
void | ssm_unschedule (ssm_sv_t *var) |
Unschedule any pending events on a variable. More... | |
ssm_value_t | ssm_new_sv_int (ssm_value_t val) |
Allocate an ssm_sv on the heap. More... | |
void | ssm_sv_assign_unsafe (ssm_sv_t *var, ssm_priority_t prio, ssm_value_t val) |
ssm_assign() without automatic reference counting. More... | |
void | ssm_sv_later_unsafe (ssm_sv_t *var, ssm_time_t when, ssm_value_t val) |
ssm_later() without automatic reference counting. More... | |
void | ssm_sv_sensitize (ssm_sv_t *var, ssm_trigger_t *trig) |
Sensitize a variable to a trigger. More... | |
void | ssm_sv_desensitize (ssm_trigger_t *trig) |
Desensitize a variable from a trigger. More... | |
#define ssm_new_sv | ( | v | ) |
#define ssm_to_sv | ( | val | ) | container_of((val).heap_ptr, ssm_sv_t, mm) |
Retrieve ssm_sv pointer pointed to by an ssm_value_t.
val | the ssm_value_t |
#define ssm_deref | ( | val | ) | (ssm_to_sv(val)->value) |
Read the value of a scheduled variable.
val | ssm_value_t that points to a scheduled variable. |
#define ssm_assign | ( | var, | |
prio, | |||
val | |||
) |
Instantaneous assignment to a scheduled variable.
Updates the value of var in the current instant, and wakes up all sensitive processes at a lower priority than the calling routine.
ssm_assign() will ssm_drop() the previous value of var and ssm_dup() the new val. If the caller already knows whether var and val reside on the heap, they may call ssm_assign_unsafe() to forego the ssm_drop() and ssm_dup() calls, but will be responsible for reference counting themselves (i.e., calling ssm_dup_unsafe() and ssm_drop_unsafe() for heap objects).
var | pointer to the scheduled variable. |
prio | priority of the calling routine. |
val | the value to be assigned to var. |
#define ssm_later | ( | var, | |
when, | |||
val | |||
) |
Delayed assignment to a scheduled variable.
Schedules a delayed assignment to var at a later time.
ssm_later() will ssm_dup() the scheduled val. If the caller already knows whether val resides on the heap, they may call ssm_later_unsafe() to forego the ssm_dup(), but will be responsible for reference counting themselves (i.e., calling ssm_dup_unsafe() for heap objects).
Overwrites any previously scheduled update, if any.
var | pointer to the scheduled variable. |
when | the time when the update should take place. |
val | the value to be assigned to var. |
SSM_INVALID_TIME | later is greater than ssm_now(). |
SSM_EXHAUSTED_EVENT_QUEUE | event queue ran out of space. |
#define ssm_sensitize | ( | var, | |
trig | |||
) | ssm_sv_sensitize(ssm_to_sv(var), trig) |
Sensitize a trigger to a scheduled variable.
Macro provided for convenience.
var | ssm_value_t pointing to a scheduled variable. |
trig | trigger to be registered on var. |
#define ssm_desensitize | ( | trig | ) | ssm_sv_desensitize(trig) |
Desensitize a trigger.
Macro provided for convenience.
trig | the trigger. |
A scheduled variable that supports scheduled updates with triggers.
Scheduled variables are heap-allocated built-in types that represent variables with reference-like semantics in SSM. These should be always allocated on the heap using ssm_new_sv().
Routines may directly assign to them in the current instant (ssm_assign()), or schedule a delayed assignment to them (ssm_later()). The last_updated time is recorded in each case, sensitive routines, i.e., triggers, are woken up.
At most one delayed assignment may be scheduled at a time, but a single update may wake any number of sensitive routines.
ssm_sv_t v
, v.mm.kind == SSM_SV_K
. void ssm_update | ( | ssm_sv_t * | sv | ) |
Perform a (delayed) update on a variable.
Schedules all routine activation records sensitive to sv in the activation queue.
Should only be called if the variable is scheduled to be updated now.
Exposed so that platform code can perform external variable updates.
sv | the variable. |
SSM_NOT_READY | sv was not scheduled to be updated now. |
Definition at line 413 of file ssm-scheduler.c.
void ssm_unschedule | ( | ssm_sv_t * | var | ) |
Unschedule any pending events on a variable.
Should be called before the variable is dropped.
Nothing happens if the variable does not have a pending event.
var | the variable. |
Definition at line 374 of file ssm-scheduler.c.
ssm_value_t ssm_new_sv_int | ( | ssm_value_t | val | ) |
Allocate an ssm_sv on the heap.
val | the initial value of the scheduled variable. |
void ssm_sv_assign_unsafe | ( | ssm_sv_t * | var, |
ssm_priority_t | prio, | ||
ssm_value_t | val | ||
) |
ssm_assign() without automatic reference counting.
var | pointer to the scheduled variable. |
prio | priority of the calling routine. |
val | the value to be assigned to var. |
Definition at line 310 of file ssm-scheduler.c.
void ssm_sv_later_unsafe | ( | ssm_sv_t * | var, |
ssm_time_t | when, | ||
ssm_value_t | val | ||
) |
ssm_later() without automatic reference counting.
Overwrites any previously scheduled update, if ssm_laterr
var | pointer to the scheduled variable. |
when | the time when the update should take place. |
val | the value to be assigned to var. |
SSM_INVALID_TIME | later is greater than ssm_now(). |
SSM_EXHAUSTED_EVENT_QUEUE | event queue ran out of space. |
Definition at line 318 of file ssm-scheduler.c.
void ssm_sv_sensitize | ( | ssm_sv_t * | var, |
ssm_trigger_t * | trig | ||
) |
Sensitize a variable to a trigger.
Adds a trigger to a scheduled variable, so that trig's activation record is awoken when the variable is updated.
This function should be called by a routine before sleeping (yielding).
var | pointer to the scheduled variable. |
trig | trigger to be registered on var. |
Definition at line 350 of file ssm-scheduler.c.
void ssm_sv_desensitize | ( | ssm_trigger_t * | trig | ) |
Desensitize a variable from a trigger.
Remove a trigger from its variable.
This function should be called by a routine after returning from sleeping.
trig | the trigger. |
Definition at line 365 of file ssm-scheduler.c.