syslog-ng source
atomic.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2012 Balabit
3  * Copyright (c) 1998-2012 Balázs Scheidler
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * As an additional exemption you are allowed to compile & link against the
20  * OpenSSL libraries as published by the OpenSSL project. See the file
21  * COPYING for details.
22  *
23  */
24 
25 #ifndef ATOMIC_H_INCLUDED
26 #define ATOMIC_H_INCLUDED
27 
28 #include "compat/glib.h"
29 
30 typedef struct
31 {
32  gint counter;
34 
35 static inline void
36 g_atomic_counter_inc(GAtomicCounter *c)
37 {
38  g_atomic_int_inc(&c->counter);
39 }
40 
41 static inline gboolean
42 g_atomic_counter_dec_and_test(GAtomicCounter *c)
43 {
44  return g_atomic_int_dec_and_test(&c->counter);
45 }
46 
47 static inline gint
48 g_atomic_counter_get(GAtomicCounter *c)
49 {
50  return g_atomic_int_get(&c->counter);
51 }
52 
53 static inline gint
54 g_atomic_counter_exchange_and_add(GAtomicCounter *c, gint val)
55 {
56  return g_atomic_int_add(&c->counter, val);
57 }
58 
59 static inline gint
60 g_atomic_counter_racy_get(GAtomicCounter *c)
61 {
62  return c->counter;
63 }
64 
65 static inline void
66 g_atomic_counter_set(GAtomicCounter *c, gint value)
67 {
68  g_atomic_int_set(&c->counter, value);
69 }
70 
71 #endif
Definition: atomic.h:31
gint counter
Definition: atomic.h:32
GString * value
Definition: test_decode.c:28