diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-11-28 20:54:20 -0500 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-07 07:40:27 -0800 |
| commit | 755dcb223e9ca2aecd2555a417247d8f55fdaf33 (patch) | |
| tree | d655c43584285446e38c90536ed4b0b4b31c15a5 /src/core/refcnt.h | |
| parent | 513f9d1b15257fdffa630e3a3d3fe85855343e41 (diff) | |
| download | nng-755dcb223e9ca2aecd2555a417247d8f55fdaf33.tar.gz nng-755dcb223e9ca2aecd2555a417247d8f55fdaf33.tar.bz2 nng-755dcb223e9ca2aecd2555a417247d8f55fdaf33.zip | |
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.
Diffstat (limited to 'src/core/refcnt.h')
| -rw-r--r-- | src/core/refcnt.h | 28 |
1 files changed, 28 insertions, 0 deletions
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. <info@staysail.tech> +// +// 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 <nng/nng.h> + +#include <core/nng_impl.h> +#include <core/platform.h> + +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 |
