Skip to content

Commit

Permalink
sm: Support attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <[email protected]>
  • Loading branch information
cole-miller committed Sep 2, 2024
1 parent 73a600e commit 8e2d685
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lib/sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ void sm_relate(const struct sm *from, const struct sm *to)
from->name, to->name, from->pid, to->pid, from->id, to->id);
}

void sm_attr(const struct sm *m, const char *k, const char *fmt, ...)
{
char v[SM_MAX_ATTR_LENGTH];
va_list ap;
va_start(ap, fmt);
vsnprintf(v, sizeof(v), fmt, ap);
va_end(ap);
tracef("%s-attr pid: %d sm_id: %" PRIu64 " %s %s |",
m->name, m->pid, m->id, k, v);
}

void sm_init(struct sm *m,
bool (*invariant)(const struct sm *, int),
bool (*is_locked)(const struct sm *),
Expand Down
5 changes: 5 additions & 0 deletions src/lib/sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define CHECK(cond) sm_check((cond), __FILE__, __LINE__, #cond)

#define SM_MAX_NAME_LENGTH 50
#define SM_MAX_ATTR_LENGTH 100

enum {
SM_PREV_NONE = -1,
Expand Down Expand Up @@ -54,5 +55,9 @@ int sm_state(const struct sm *m);
bool sm_check(bool b, const char *f, int n, const char *s);
/* Relates one state machine to another for observability. */
void sm_relate(const struct sm *from, const struct sm *to);
/**
* Records an attribute of a state machine for observability.
*/
void sm_attr(const struct sm *m, const char *k, const char *fmt, ...);

#endif /* __LIB_SM__ */

0 comments on commit 8e2d685

Please sign in to comment.