chiark / gitweb /
tree-wide: remove Lennart's copyright lines
[elogind.git] / src / basic / refcnt.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /* A type-safe atomic refcounter.
5  *
6  * DO NOT USE THIS UNLESS YOU ACTUALLY CARE ABOUT THREAD SAFETY! */
7
8 typedef struct {
9         volatile unsigned _value;
10 } RefCount;
11
12 #define REFCNT_GET(r) ((r)._value)
13 #define REFCNT_INC(r) (__sync_add_and_fetch(&(r)._value, 1))
14 #define REFCNT_DEC(r) (__sync_sub_and_fetch(&(r)._value, 1))
15
16 #define REFCNT_INIT ((RefCount) { ._value = 1 })