diff --git a/lib/filterx/filterx-expr.c b/lib/filterx/filterx-expr.c index 922ed11acb..0877aad112 100644 --- a/lib/filterx/filterx-expr.c +++ b/lib/filterx/filterx-expr.c @@ -65,7 +65,7 @@ filterx_expr_free_method(FilterXExpr *self) void filterx_expr_init_instance(FilterXExpr *self) { - self->ref_cnt = 1; + g_atomic_counter_set(&self->ref_cnt, 1); self->free_fn = filterx_expr_free_method; } @@ -83,7 +83,7 @@ filterx_expr_ref(FilterXExpr *self) if (!self) return NULL; - self->ref_cnt++; + g_atomic_counter_inc(&self->ref_cnt); return self; } @@ -93,7 +93,7 @@ filterx_expr_unref(FilterXExpr *self) if (!self) return; - if (--self->ref_cnt == 0) + if (g_atomic_counter_dec_and_test(&self->ref_cnt)) { self->free_fn(self); g_free(self); diff --git a/lib/filterx/filterx-expr.h b/lib/filterx/filterx-expr.h index fbf8bc7ceb..d5b3c59b13 100644 --- a/lib/filterx/filterx-expr.h +++ b/lib/filterx/filterx-expr.h @@ -26,10 +26,11 @@ #include "filterx-object.h" #include "cfg-lexer.h" +#include "atomic.h" struct _FilterXExpr { - guint32 ref_cnt; + GAtomicCounter ref_cnt; const gchar *type; guint32 ignore_falsy_result:1, suppress_from_trace:1;