GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_ref_count.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2024 Cyril Hrubis <metan@ucw.cz>
4 */
5
10
11#ifndef CORE_GP_REF_COUNT_H
12#define CORE_GP_REF_COUNT_H
13
14#include <limits.h>
15#include <stdbool.h>
16
17typedef unsigned int gp_refcnt;
18
19static inline bool gp_refcnt_inc(gp_refcnt *self)
20{
21 gp_refcnt new_val, old_val;
22
23 do {
24 old_val = *self;
25
26 if (!old_val)
27 return false;
28
29 if (old_val == UINT_MAX)
30 return true;
31
32 new_val = old_val + 1;
33
34 } while (!__sync_bool_compare_and_swap(self, old_val, new_val));
35
36 return true;
37}
38
39static inline bool gp_refcnt_dec(gp_refcnt *self)
40{
41 gp_refcnt new_val, old_val;
42
43 do {
44 old_val = *self;
45
46 if (old_val == UINT_MAX)
47 return false;
48
49
50 }
51}
52
53#endif /* CORE_GP_REF_COUNT_H */