2023-01-12 19:16:52 +01:00
|
|
|
/* Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC)
|
2022-09-19 12:39:02 +02:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
2021-10-26 18:42:41 +02:00
|
|
|
|
2023-01-12 19:16:52 +01:00
|
|
|
#ifndef CHAN_H
|
|
|
|
#define CHAN_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "value.h"
|
|
|
|
|
|
|
|
#define MAX_CHAN_STACK 512
|
|
|
|
#define MAX_CHAN_NAME 512
|
|
|
|
|
|
|
|
enum chan_type {
|
|
|
|
CHAN_SINGLE = 0,
|
|
|
|
CHAN_STACK = 1,
|
|
|
|
CHAN_MAXTYPE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct chan_stack {
|
|
|
|
int n;
|
|
|
|
struct value values[MAX_CHAN_STACK];
|
|
|
|
};
|
|
|
|
|
|
|
|
union chan_data {
|
|
|
|
struct chan_stack stack;
|
|
|
|
struct value value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct chan;
|
|
|
|
|
|
|
|
typedef int (*chan_cb_t)(struct chan *chan, void *ptr);
|
|
|
|
|
|
|
|
struct chan {
|
|
|
|
char name[MAX_CHAN_NAME];
|
|
|
|
enum chan_type type;
|
|
|
|
union chan_data data;
|
|
|
|
int is_dirty;
|
2023-01-10 18:30:51 +01:00
|
|
|
int allow_dirty_write;
|
2023-01-12 19:16:52 +01:00
|
|
|
struct value err_value;
|
|
|
|
struct value last_value;
|
|
|
|
chan_cb_t dirty_cb;
|
|
|
|
void *dirty_arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
//int chan_enable(struct chan *chan);
|
|
|
|
//int chan_disable(struct chan *chan);
|
|
|
|
//int chan_is_enabled(const struct chan *chan);
|
|
|
|
|
|
|
|
void chan_init(struct chan *chan, enum chan_type type, const char *name);
|
|
|
|
int chan_set(struct chan *chan, struct value value);
|
|
|
|
int chan_push(struct chan *chan, struct value value);
|
|
|
|
int chan_pop(struct chan *chan, struct value expected);
|
|
|
|
int chan_read(struct chan *chan, struct value *value);
|
|
|
|
enum chan_type chan_get_type(struct chan *chan);
|
2023-01-10 18:30:51 +01:00
|
|
|
int chan_flush(struct chan *chan);
|
|
|
|
void chan_dirty_write(struct chan *chan, int allow);
|
2023-01-12 19:16:52 +01:00
|
|
|
|
|
|
|
/* Called when it becomes dirty */
|
|
|
|
void chan_set_dirty_cb(struct chan *chan, chan_cb_t func, void *arg);
|
|
|
|
|
|
|
|
#endif /* CHAN_H */
|