reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
tag.h
Go to the documentation of this file.
1
14
15#ifndef TAG_H
16#define TAG_H
17
19#define NSEC(t) ((interval_t)(t * 1LL))
21#define NSECS(t) ((interval_t)(t * 1LL))
23#define USEC(t) ((interval_t)(t * 1000LL))
25#define USECS(t) ((interval_t)(t * 1000LL))
27#define MSEC(t) ((interval_t)(t * 1000000LL))
29#define MSECS(t) ((interval_t)(t * 1000000LL))
31#define SEC(t) ((interval_t)(t * 1000000000LL))
33#define SECS(t) ((interval_t)(t * 1000000000LL))
35#define SECOND(t) ((interval_t)(t * 1000000000LL))
37#define SECONDS(t) ((interval_t)(t * 1000000000LL))
39#define MINUTE(t) ((interval_t)(t * 60000000000LL))
41#define MINUTES(t) ((interval_t)(t * 60000000000LL))
43#define HOUR(t) ((interval_t)(t * 3600000000000LL))
45#define HOURS(t) ((interval_t)(t * 3600000000000LL))
47#define DAY(t) ((interval_t)(t * 86400000000000LL))
49#define DAYS(t) ((interval_t)(t * 86400000000000LL))
51#define WEEK(t) ((interval_t)(t * 604800000000000LL))
53#define WEEKS(t) ((interval_t)(t * 604800000000000LL))
54
56#define NEVER ((interval_t)LLONG_MIN)
58#define NEVER_MICROSTEP 0u
60#define FOREVER ((interval_t)LLONG_MAX)
62#define FOREVER_MICROSTEP UINT_MAX
64#define NEVER_TAG \
65 (tag_t) { .time = NEVER, .microstep = NEVER_MICROSTEP }
66// Need a separate initializer expression to comply with some C compilers
68#define NEVER_TAG_INITIALIZER {NEVER, NEVER_MICROSTEP}
70#define FOREVER_TAG \
71 (tag_t) { .time = FOREVER, .microstep = FOREVER_MICROSTEP }
72// Need a separate initializer expression to comply with some C compilers
74#define FOREVER_TAG_INITIALIZER {FOREVER, FOREVER_MICROSTEP}
76#define ZERO_TAG (tag_t){.time = 0LL, .microstep = 0u}
77
84#define CHECK_TIMEOUT(start, duration) (lf_time_physical() > ((start) + (duration)))
85
87#define BILLION ((instant_t)1000000000LL)
88
89#include <stdint.h>
90#include <stddef.h>
91#include <limits.h>
92
94
101typedef int64_t instant_t;
102
107typedef int64_t interval_t;
108
113typedef uint32_t microstep_t;
114
123
125
132tag_t lf_tag(void* env);
133
149
159
169
183int lf_tag_compare(tag_t tag1, tag_t tag2);
184
194
204
226
245
254
266
276
287
297
308
326#define LF_TIME_BUFFER_LENGTH 64
327
345size_t lf_readable_time(char* buffer, instant_t time);
346
360size_t lf_comma_separated_time(char* buffer, instant_t time);
361
362#endif // TAG_H
instant_t lf_time_add(instant_t a, interval_t b)
Return the sum of an interval and an instant, saturating on overflow and underflow.
#define lf_tag()
Return the current tag of the environment invoking this reaction.
Definition reaction_macros.h:198
size_t lf_readable_time(char *buffer, instant_t time)
Store into the specified buffer a string giving a human-readable rendition of the specified time.
tag_t lf_tag_max(tag_t tag1, tag_t tag2)
Return the greater out of two tags.
#define lf_time_logical()
Return the current logical time in nanoseconds of the environment invoking this reaction.
Definition reaction_macros.h:204
int lf_tag_compare(tag_t tag1, tag_t tag2)
Compare two tags.
instant_t lf_time_physical(void)
Return the current physical time in nanoseconds.
#define lf_time_logical_elapsed()
Return the current logical time of the environment invoking this reaction relative to the start time ...
Definition reaction_macros.h:211
tag_t lf_tag_min(tag_t tag1, tag_t tag2)
Return the lesser out of two tags.
int64_t instant_t
Time instant.
Definition tag.h:101
instant_t lf_time_start(void)
Return the physical and logical time of the start of execution in nanoseconds.
instant_t lf_time_subtract(instant_t a, interval_t b)
Return an instant minus an interval, saturating on overflow and underflow.
instant_t lf_time_physical_elapsed(void)
Return the elapsed physical time in nanoseconds.
tag_t lf_tag_add(tag_t a, tag_t b)
Add two tags.
uint32_t microstep_t
Microstep.
Definition tag.h:113
size_t lf_comma_separated_time(char *buffer, instant_t time)
Print a non-negative time value in nanoseconds with commas separating thousands into the specified bu...
int64_t interval_t
Interval of time.
Definition tag.h:107
tag_t lf_delay_tag(tag_t tag, interval_t interval)
Delay a tag by the specified time interval to realize the "after" keyword.
tag_t lf_tag_latest_earlier(tag_t tag)
Return the greatest tag earlier than the given tag.
tag_t lf_delay_strict(tag_t tag, interval_t interval)
Return the latest tag strictly less than the specified tag plus the interval, unless tag is NEVER or ...
A tag is a time, microstep pair.
Definition tag.h:119
microstep_t microstep
Definition tag.h:121
instant_t time
Definition tag.h:120