Move chan_read() to a inline function in chan.h

This commit is contained in:
Rodrigo Arias 2023-03-08 16:17:41 +01:00 committed by Rodrigo Arias Mallo
parent 43fa556fa9
commit f3bcdeccd1
2 changed files with 18 additions and 11 deletions

View File

@ -204,7 +204,7 @@ chan_pop(struct chan *chan, struct value evalue)
static void
get_value(struct chan *chan, struct value *value)
{
if (chan->type == CHAN_SINGLE) {
if (likely(chan->type == CHAN_SINGLE)) {
*value = chan->data.value;
} else {
struct chan_stack *stack = &chan->data.stack;
@ -215,15 +215,6 @@ get_value(struct chan *chan, struct value *value)
}
}
/** Reads the current value of a channel */
int
chan_read(struct chan *chan, struct value *value)
{
get_value(chan, value);
return 0;
}
/** Remove the dirty state */
int
chan_flush(struct chan *chan)

View File

@ -53,11 +53,27 @@ struct chan {
char name[MAX_CHAN_NAME];
};
/** Reads the current value of a channel */
USE_RET static inline int
chan_read(struct chan *chan, struct value *value)
{
if (likely(chan->type == CHAN_SINGLE)) {
*value = chan->data.value;
} else {
struct chan_stack *stack = &chan->data.stack;
if (stack->n > 0)
*value = stack->values[stack->n - 1];
else
*value = value_null();
}
return 0;
}
void chan_init(struct chan *chan, enum chan_type type, const char *fmt, ...);
USE_RET int chan_set(struct chan *chan, struct value value);
USE_RET int chan_push(struct chan *chan, struct value value);
USE_RET int chan_pop(struct chan *chan, struct value expected);
USE_RET int chan_read(struct chan *chan, struct value *value);
USE_RET enum chan_type chan_get_type(struct chan *chan);
USE_RET int chan_flush(struct chan *chan);
void chan_prop_set(struct chan *chan, enum chan_prop prop, int value);