]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
e4ee6e5c LP |
2 | #pragma once |
3 | ||
57de20dd LP |
4 | /* A type-safe atomic refcounter. |
5 | * | |
6 | * DO NOT USE THIS UNLESS YOU ACTUALLY CARE ABOUT THREAD SAFETY! */ | |
e4ee6e5c LP |
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 }) |