2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2013-05-16 21:52:35 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2013 Lennart Poettering
|
|
|
|
***/
|
|
|
|
|
2015-08-26 21:04:38 +02:00
|
|
|
/* A type-safe atomic refcounter.
|
|
|
|
*
|
|
|
|
* DO NOT USE THIS UNLESS YOU ACTUALLY CARE ABOUT THREAD SAFETY! */
|
2013-05-16 21:52:35 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
volatile unsigned _value;
|
|
|
|
} RefCount;
|
|
|
|
|
|
|
|
#define REFCNT_GET(r) ((r)._value)
|
|
|
|
#define REFCNT_INC(r) (__sync_add_and_fetch(&(r)._value, 1))
|
|
|
|
#define REFCNT_DEC(r) (__sync_sub_and_fetch(&(r)._value, 1))
|
|
|
|
|
|
|
|
#define REFCNT_INIT ((RefCount) { ._value = 1 })
|