Move chan_read() to a inline function in chan.h
This commit is contained in:
parent
43fa556fa9
commit
f3bcdeccd1
@ -204,7 +204,7 @@ chan_pop(struct chan *chan, struct value evalue)
|
|||||||
static void
|
static void
|
||||||
get_value(struct chan *chan, struct value *value)
|
get_value(struct chan *chan, struct value *value)
|
||||||
{
|
{
|
||||||
if (chan->type == CHAN_SINGLE) {
|
if (likely(chan->type == CHAN_SINGLE)) {
|
||||||
*value = chan->data.value;
|
*value = chan->data.value;
|
||||||
} else {
|
} else {
|
||||||
struct chan_stack *stack = &chan->data.stack;
|
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 */
|
/** Remove the dirty state */
|
||||||
int
|
int
|
||||||
chan_flush(struct chan *chan)
|
chan_flush(struct chan *chan)
|
||||||
|
@ -53,11 +53,27 @@ struct chan {
|
|||||||
char name[MAX_CHAN_NAME];
|
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, ...);
|
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_set(struct chan *chan, struct value value);
|
||||||
USE_RET int chan_push(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_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 enum chan_type chan_get_type(struct chan *chan);
|
||||||
USE_RET int chan_flush(struct chan *chan);
|
USE_RET int chan_flush(struct chan *chan);
|
||||||
void chan_prop_set(struct chan *chan, enum chan_prop prop, int value);
|
void chan_prop_set(struct chan *chan, enum chan_prop prop, int value);
|
||||||
|
Loading…
Reference in New Issue
Block a user