From 755dcb223e9ca2aecd2555a417247d8f55fdaf33 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 28 Nov 2024 20:54:20 -0500 Subject: fixes #1408 Reference count as a first class type This starts by using this for the nni_pipe, but we will use it for the other primary objects as well. This should simplify the tear down and hopefully eliminate some races. It does mean that pipe destruction goes through an additional context switch, for now at least. This shouldn't be on the hot data path anyway. --- src/core/refcnt.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/core/refcnt.h (limited to 'src/core/refcnt.h') diff --git a/src/core/refcnt.h b/src/core/refcnt.h new file mode 100644 index 00000000..9878ba50 --- /dev/null +++ b/src/core/refcnt.h @@ -0,0 +1,28 @@ +// Copyright 2024 Staysail Systems, Inc. +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +#ifndef CORE_REFCNT_H +#define CORE_REFCNT_H + +#include + +#include +#include + +typedef struct { + nni_atomic_int rc_cnt; + void (*rc_fini)(void *); + void *rc_data; +} nni_refcnt; + +extern void nni_refcnt_init( + nni_refcnt *rc, unsigned value, void *v, void (*fini)(void *)); +extern void nni_refcnt_hold(nni_refcnt *rc); +extern void nni_refcnt_rele(nni_refcnt *rc); + +#endif // CORE_REFCNT_H -- cgit v1.2.3-70-g09d2