1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2013 Lennart Poettering
10 /* A type-safe atomic refcounter.
12 * DO NOT USE THIS UNLESS YOU ACTUALLY CARE ABOUT THREAD SAFETY! */
15 volatile unsigned _value;
18 #define REFCNT_GET(r) ((r)._value)
19 #define REFCNT_INC(r) (__sync_add_and_fetch(&(r)._value, 1))
20 #define REFCNT_DEC(r) (__sync_sub_and_fetch(&(r)._value, 1))
22 #define REFCNT_INIT ((RefCount) { ._value = 1 })