mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-08 12:18:42 +00:00
Filters: If somebody doesn't like _Thread_local, don't fail for now, just be a little slower.
When the parallel execution comes into place, we'll likely enforce this C11 feature. It's much simpler and also faster than pthread_[sg]etspecific().
This commit is contained in:
parent
23e3b1e665
commit
6479e403ef
21
aclocal.m4
vendored
21
aclocal.m4
vendored
@ -1,6 +1,25 @@
|
|||||||
dnl ** Additional Autoconf tests for BIRD configure script
|
dnl ** Additional Autoconf tests for BIRD configure script
|
||||||
dnl ** (c) 1999 Martin Mares <mj@ucw.cz>
|
dnl ** (c) 1999 Martin Mares <mj@ucw.cz>
|
||||||
|
|
||||||
|
AC_DEFUN([BIRD_CHECK_THREAD_LOCAL],
|
||||||
|
[
|
||||||
|
AC_CACHE_CHECK(
|
||||||
|
[whether _Thread_local is known],
|
||||||
|
[bird_cv_thread_local],
|
||||||
|
AC_COMPILE_IFELSE([
|
||||||
|
AC_LANG_PROGRAM(
|
||||||
|
[
|
||||||
|
_Thread_local static int x = 42;
|
||||||
|
],
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
],
|
||||||
|
[bird_cv_thread_local=yes],
|
||||||
|
[bird_cv_thread_local=no]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
])
|
||||||
|
|
||||||
AC_DEFUN([BIRD_CHECK_PTHREADS],
|
AC_DEFUN([BIRD_CHECK_PTHREADS],
|
||||||
[
|
[
|
||||||
bird_tmp_cflags="$CFLAGS"
|
bird_tmp_cflags="$CFLAGS"
|
||||||
@ -134,7 +153,7 @@ AC_DEFUN([BIRD_CHECK_ANDROID_LOG],
|
|||||||
AC_DEFUN([BIRD_CHECK_LTO],
|
AC_DEFUN([BIRD_CHECK_LTO],
|
||||||
[
|
[
|
||||||
bird_tmp_cflags="$CFLAGS"
|
bird_tmp_cflags="$CFLAGS"
|
||||||
bird_tmp_ldflags="$CFLAGS"
|
bird_tmp_ldflags="$LDFLAGS"
|
||||||
CFLAGS="-flto"
|
CFLAGS="-flto"
|
||||||
LDFLAGS="-flto"
|
LDFLAGS="-flto"
|
||||||
|
|
||||||
|
@ -115,6 +115,11 @@ if test -z "$GCC" ; then
|
|||||||
AC_MSG_ERROR([This program requires the GNU C Compiler.])
|
AC_MSG_ERROR([This program requires the GNU C Compiler.])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
BIRD_CHECK_THREAD_LOCAL
|
||||||
|
if test "$bird_cv_thread_local" = yes ; then
|
||||||
|
AC_DEFINE([HAVE_THREAD_LOCAL], [1], [Define to 1 if _Thread_local is available])
|
||||||
|
fi
|
||||||
|
|
||||||
if test "$enable_pthreads" != no ; then
|
if test "$enable_pthreads" != no ; then
|
||||||
BIRD_CHECK_PTHREADS
|
BIRD_CHECK_PTHREADS
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
#include "filter/data.h"
|
#include "filter/data.h"
|
||||||
|
|
||||||
/* Internal filter state, to be allocated on stack when executing filters */
|
/* Internal filter state, to be allocated on stack when executing filters */
|
||||||
_Thread_local struct filter_state {
|
struct filter_state {
|
||||||
/* The route we are processing. This may be NULL to indicate no route available. */
|
/* The route we are processing. This may be NULL to indicate no route available. */
|
||||||
struct rte **rte;
|
struct rte **rte;
|
||||||
|
|
||||||
@ -63,7 +63,14 @@ _Thread_local struct filter_state {
|
|||||||
struct linpool *pool;
|
struct linpool *pool;
|
||||||
struct buffer buf;
|
struct buffer buf;
|
||||||
int flags;
|
int flags;
|
||||||
} filter_state;
|
};
|
||||||
|
|
||||||
|
#if HAVE_THREAD_LOCAL
|
||||||
|
_Thread_local static struct filter_state filter_state;
|
||||||
|
#define FS_INIT(...) filter_state = (struct filter_state) { __VA_ARGS__ }
|
||||||
|
#else
|
||||||
|
#define FS_INIT(...) struct filter_state filter_state = { __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);
|
||||||
|
|
||||||
@ -275,11 +282,11 @@ 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 */
|
||||||
filter_state = (struct filter_state) {
|
FS_INIT(
|
||||||
.rte = rte,
|
.rte = rte,
|
||||||
.pool = tmp_pool,
|
.pool = tmp_pool,
|
||||||
.flags = flags,
|
.flags = flags,
|
||||||
};
|
);
|
||||||
|
|
||||||
LOG_BUFFER_INIT(filter_state.buf);
|
LOG_BUFFER_INIT(filter_state.buf);
|
||||||
|
|
||||||
@ -338,10 +345,10 @@ 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)
|
||||||
{
|
{
|
||||||
filter_state = (struct filter_state) {
|
FS_INIT(
|
||||||
.rte = rte,
|
.rte = rte,
|
||||||
.pool = tmp_pool,
|
.pool = tmp_pool,
|
||||||
};
|
);
|
||||||
|
|
||||||
LOG_BUFFER_INIT(filter_state.buf);
|
LOG_BUFFER_INIT(filter_state.buf);
|
||||||
|
|
||||||
@ -360,9 +367,9 @@ 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)
|
||||||
{
|
{
|
||||||
filter_state = (struct filter_state) {
|
FS_INIT(
|
||||||
.pool = tmp_pool,
|
.pool = tmp_pool,
|
||||||
};
|
);
|
||||||
|
|
||||||
LOG_BUFFER_INIT(filter_state.buf);
|
LOG_BUFFER_INIT(filter_state.buf);
|
||||||
|
|
||||||
@ -379,9 +386,9 @@ 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 */
|
||||||
filter_state = (struct filter_state) {
|
FS_INIT(
|
||||||
.pool = cfg_mem,
|
.pool = cfg_mem,
|
||||||
};
|
);
|
||||||
|
|
||||||
struct f_val val;
|
struct f_val val;
|
||||||
|
|
||||||
|
@ -73,6 +73,12 @@ 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
|
||||||
|
#define THREAD_LOCAL _Thread_local
|
||||||
|
#else
|
||||||
|
#define THREAD_LOCAL
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Microsecond time */
|
/* Microsecond time */
|
||||||
|
|
||||||
typedef s64 btime;
|
typedef s64 btime;
|
||||||
|
Loading…
Reference in New Issue
Block a user