Skip to content

Commit

Permalink
filterx-expr: make ref_cnt atomic
Browse files Browse the repository at this point in the history
Signed-off-by: László Várady <[email protected]>
  • Loading branch information
MrAnno committed Aug 9, 2024
1 parent fcf439f commit fe5828f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/filterx/filterx-expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/filterx/filterx-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit fe5828f

Please sign in to comment.