From fe5828f20c5d2f254d1bf08610b3dd43177e2a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20V=C3=A1rady?= Date: Fri, 9 Aug 2024 15:52:25 +0200 Subject: [PATCH] filterx-expr: make ref_cnt atomic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: László Várady --- lib/filterx/filterx-expr.c | 6 +++--- lib/filterx/filterx-expr.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) 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;