0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 01:31:55 +00:00

Filter: Simpler filter context allocation

This commit is contained in:
Maria Matejka 2019-07-15 15:23:35 +02:00
parent f634adc7dc
commit 3782454e8d
2 changed files with 21 additions and 24 deletions

View File

@ -93,13 +93,8 @@ struct filter_state {
int flags; int flags;
}; };
#if HAVE_THREAD_LOCAL
_Thread_local static struct filter_state filter_state; _Thread_local static struct filter_state filter_state;
_Thread_local static struct filter_stack filter_stack; _Thread_local static struct filter_stack filter_stack;
#define FS_INIT(...) filter_state = (struct filter_state) { .stack = &filter_stack, __VA_ARGS__ }
#else
#define FS_INIT(...) struct filter_state filter_state = { .stack = alloca(sizeof(struct filter_stack)), __VA_ARGS__ };
#endif
void (*bt_assert_hook)(int result, const struct f_line_item *assert); void (*bt_assert_hook)(int result, const struct f_line_item *assert);
@ -279,11 +274,12 @@ f_run(const struct filter *filter, struct rte **rte, struct linpool *tmp_pool, i
DBG( "Running filter `%s'...", filter->name ); DBG( "Running filter `%s'...", filter->name );
/* Initialize the filter state */ /* Initialize the filter state */
FS_INIT( filter_state = (struct filter_state) {
.rte = rte, .stack = &filter_stack,
.pool = tmp_pool, .rte = rte,
.flags = flags, .pool = tmp_pool,
); .flags = flags,
};
LOG_BUFFER_INIT(filter_state.buf); LOG_BUFFER_INIT(filter_state.buf);
@ -342,10 +338,11 @@ f_run(const struct filter *filter, struct rte **rte, struct linpool *tmp_pool, i
enum filter_return enum filter_return
f_eval_rte(const struct f_line *expr, struct rte **rte, struct linpool *tmp_pool) f_eval_rte(const struct f_line *expr, struct rte **rte, struct linpool *tmp_pool)
{ {
FS_INIT( filter_state = (struct filter_state) {
.rte = rte, .stack = &filter_stack,
.pool = tmp_pool, .rte = rte,
); .pool = tmp_pool,
};
LOG_BUFFER_INIT(filter_state.buf); LOG_BUFFER_INIT(filter_state.buf);
@ -364,9 +361,10 @@ f_eval_rte(const struct f_line *expr, struct rte **rte, struct linpool *tmp_pool
enum filter_return enum filter_return
f_eval(const struct f_line *expr, struct linpool *tmp_pool, struct f_val *pres) f_eval(const struct f_line *expr, struct linpool *tmp_pool, struct f_val *pres)
{ {
FS_INIT( filter_state = (struct filter_state) {
.pool = tmp_pool, .stack = &filter_stack,
); .pool = tmp_pool,
};
LOG_BUFFER_INIT(filter_state.buf); LOG_BUFFER_INIT(filter_state.buf);
@ -383,9 +381,10 @@ uint
f_eval_int(const struct f_line *expr) f_eval_int(const struct f_line *expr)
{ {
/* Called independently in parse-time to eval expressions */ /* Called independently in parse-time to eval expressions */
FS_INIT( filter_state = (struct filter_state) {
.pool = cfg_mem, .stack = &filter_stack,
); .pool = cfg_mem,
};
struct f_val val; struct f_val val;

View File

@ -73,10 +73,8 @@ static inline int u64_cmp(u64 i1, u64 i2)
#define UNUSED __attribute__((unused)) #define UNUSED __attribute__((unused))
#define PACKED __attribute__((packed)) #define PACKED __attribute__((packed))
#ifdef HAVE_THREAD_LOCAL #ifndef HAVE_THREAD_LOCAL
#define THREAD_LOCAL _Thread_local #define _Thread_local
#else
#define THREAD_LOCAL
#endif #endif
/* Microsecond time */ /* Microsecond time */