]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Simpler filter context allocation
authorMaria Matejka <mq@ucw.cz>
Mon, 15 Jul 2019 13:23:35 +0000 (15:23 +0200)
committerMaria Matejka <mq@ucw.cz>
Mon, 15 Jul 2019 13:46:36 +0000 (15:46 +0200)
filter/filter.c
lib/birdlib.h

index 2aa2f629e9144edc3f7906ff056aedd5f2d0ae54..35bd75e613e4250fad462cf32080f94542e4459f 100644 (file)
@@ -93,13 +93,8 @@ struct filter_state {
   int flags;
 };
 
-#if HAVE_THREAD_LOCAL
 _Thread_local static struct filter_state filter_state;
 _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);
 
@@ -279,11 +274,12 @@ f_run(const struct filter *filter, struct rte **rte, struct linpool *tmp_pool, i
   DBG( "Running filter `%s'...", filter->name );
 
   /* Initialize the filter state */
-  FS_INIT(
-      .rte = rte,
-      .pool = tmp_pool,
-      .flags = flags,
-      );
+  filter_state = (struct filter_state) {
+    .stack = &filter_stack,
+    .rte = rte,
+    .pool = tmp_pool,
+    .flags = flags,
+  };
 
   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
 f_eval_rte(const struct f_line *expr, struct rte **rte, struct linpool *tmp_pool)
 {
-  FS_INIT(
-      .rte = rte,
-      .pool = tmp_pool,
-      );
+  filter_state = (struct filter_state) {
+    .stack = &filter_stack,
+    .rte = rte,
+    .pool = tmp_pool,
+  };
 
   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
 f_eval(const struct f_line *expr, struct linpool *tmp_pool, struct f_val *pres)
 {
-  FS_INIT(
-      .pool = tmp_pool,
-      );
+  filter_state = (struct filter_state) {
+    .stack = &filter_stack,
+    .pool = tmp_pool,
+  };
 
   LOG_BUFFER_INIT(filter_state.buf);
 
@@ -383,9 +381,10 @@ uint
 f_eval_int(const struct f_line *expr)
 {
   /* Called independently in parse-time to eval expressions */
-  FS_INIT(
-      .pool = cfg_mem,
-      );
+  filter_state = (struct filter_state) {
+    .stack = &filter_stack,
+    .pool = cfg_mem,
+  };
 
   struct f_val val;
 
index 9743da32d646f1d4d95b4fbabd8c43c59b6a2cdf..30ea433c3ddcd37888b25a72f205de569691ec05 100644 (file)
@@ -73,10 +73,8 @@ static inline int u64_cmp(u64 i1, u64 i2)
 #define UNUSED __attribute__((unused))
 #define PACKED __attribute__((packed))
 
-#ifdef HAVE_THREAD_LOCAL
-#define THREAD_LOCAL _Thread_local
-#else
-#define THREAD_LOCAL
+#ifndef HAVE_THREAD_LOCAL
+#define _Thread_local
 #endif
 
 /* Microsecond time */