ssm  0.0.2
Runtime Library for the Sparse Synchronous Model
Time

SSM timestamps are 64-bit values which should never wraparound, and are represented by ssm_time_t. More...

Discussion

SSM timestamps are 64-bit values which should never wraparound, and are represented by ssm_time_t.

The runtime library maintains a monotonically increasing "current time" which can be read using ssm_now().

For portability reasons, this particular runtime implementation uses nanoseconds as its time base; it is the responsibility of platform code to convert this resolution to the tick rate of the hardware timer. See https://github.com/ssm-lang/ssm-runtime/pull/1.

Data Structures

struct  ssm_time
 Heap-allocated time values. More...
 

Macros

#define SSM_NEVER   UINT64_MAX
 Time indicating something will never happen. More...
 
#define SSM_NANOSECOND   1L
 Ticks per nanosecond. More...
 
#define SSM_MICROSECOND   (SSM_NANOSECOND * 1000L)
 Ticks per microsecond. More...
 
#define SSM_MILLISECOND   (SSM_MICROSECOND * 1000L)
 Ticks per millisecond. More...
 
#define SSM_SECOND   (SSM_MILLISECOND * 1000L)
 Ticks per second. More...
 
#define SSM_MINUTE   (SSM_SECOND * 60L)
 Ticks per minute. More...
 
#define SSM_HOUR   (SSM_MINUTE * 60L)
 Ticks per hour. More...
 
#define ssm_new_time(t)
 
#define ssm_time_read(v)   (container_of((v).heap_ptr, struct ssm_time, mm)->time)
 Read the heap-allocated time pointed to by an ssm_value_t. More...
 

Typedefs

typedef uint64_t ssm_time_t
 Absolute time; never to overflow. More...
 

Functions

ssm_time_t ssm_next_event_time (void)
 The time of the next event in the event queue. More...
 
void ssm_reset (void)
 Reset the scheduler. More...
 
void ssm_set_now (ssm_time_t next)
 Advance the current model time. More...
 
ssm_time_t ssm_now (void)
 The current model time. More...
 
ssm_value_t ssm_new_time_int (ssm_time_t time)
 Allocate a ssm_time on the heap. More...
 

Macro Definition Documentation

◆ SSM_NEVER

#define SSM_NEVER   UINT64_MAX

Time indicating something will never happen.

The value of this must be derived from the underlying type of ssm_time_t.

Definition at line 417 of file ssm.h.

◆ SSM_NANOSECOND

#define SSM_NANOSECOND   1L

Ticks per nanosecond.

Definition at line 420 of file ssm.h.

◆ SSM_MICROSECOND

#define SSM_MICROSECOND   (SSM_NANOSECOND * 1000L)

Ticks per microsecond.

Definition at line 422 of file ssm.h.

◆ SSM_MILLISECOND

#define SSM_MILLISECOND   (SSM_MICROSECOND * 1000L)

Ticks per millisecond.

Definition at line 424 of file ssm.h.

◆ SSM_SECOND

#define SSM_SECOND   (SSM_MILLISECOND * 1000L)

Ticks per second.

Definition at line 426 of file ssm.h.

◆ SSM_MINUTE

#define SSM_MINUTE   (SSM_SECOND * 60L)

Ticks per minute.

Definition at line 428 of file ssm.h.

◆ SSM_HOUR

#define SSM_HOUR   (SSM_MINUTE * 60L)

Ticks per hour.

Definition at line 430 of file ssm.h.

◆ ssm_new_time

#define ssm_new_time (   t)
Value:
(fprintf(stderr, "%s:%d:ssm_new_time()\n", __FILE__, __LINE__), \
ssm_new_time_int(t))

Definition at line 447 of file ssm.h.

◆ ssm_time_read

#define ssm_time_read (   v)    (container_of((v).heap_ptr, struct ssm_time, mm)->time)

Read the heap-allocated time pointed to by an ssm_value_t.

Note
The behavior of using this macro on an ssm_value_t that does not point to an ssm_time is undefined.
The behavior of using the result of this macro as an l-value is undefined.
Parameters
vthe ssm_value_t
Returns
the ssm_time_t in the heap.

Definition at line 464 of file ssm.h.

Typedef Documentation

◆ ssm_time_t

typedef uint64_t ssm_time_t

Absolute time; never to overflow.

Definition at line 399 of file ssm.h.

Function Documentation

◆ ssm_next_event_time()

ssm_time_t ssm_next_event_time ( void  )

The time of the next event in the event queue.

Used to determine whether and when to invoke ssm_tick().

Note
Intended for platform code; should not be used in user code.
Returns
the next event time, or SSM_NEVER if the event queue is empty.

Definition at line 391 of file ssm-scheduler.c.

◆ ssm_reset()

void ssm_reset ( void  )

Reset the scheduler.

Set now to 0; clear the event and activation record queues.

This does not need to be called before calling ssm_tick() for the first time; the global state automatically starts initialized.

Note
Intended for platform code; should not be used in user code.

Definition at line 395 of file ssm-scheduler.c.

◆ ssm_set_now()

void ssm_set_now ( ssm_time_t  next)

Advance the current model time.

next must be later than ssm_now(), and earlier than or equal to ssm_next_event_time().

Exposed so that platform code can perform external variable updates, to implement external inputs.

Note
Intended for platform code; should not be used in user code.
Parameters
nextthe time to advance to.
Exceptions
SSM_INVALID_TIMEnext is earlier than or equal to now.
SSM_NOT_READYnext is later than the earliest queued event.

Definition at line 401 of file ssm-scheduler.c.

◆ ssm_now()

ssm_time_t ssm_now ( void  )

The current model time.

Returns
the current model time.

Definition at line 267 of file ssm-scheduler.c.

◆ ssm_new_time_int()

ssm_value_t ssm_new_time_int ( ssm_time_t  time)

Allocate a ssm_time on the heap.

Parameters
timewhat the heap-allocated time field is initialized to.
Returns
ssm_value_t pointing to the heap-allocated ssm_time.

ssm_value_t ssm_new_time(ssm_time_t time)

Definition at line 266 of file ssm-mem.c.