summaryrefslogtreecommitdiffstats
path: root/include/libtf/atomic.h
blob: 8ebe5f8d8214441513bb0e659c843f5f4054d931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* atomic.h - wrapper for atomic gcc built-ins
 *
 * Copyright (C) 2009 Timo Teräs <timo.teras@iki.fi>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 or later as
 * published by the Free Software Foundation.
 *
 * See http://www.gnu.org/ for details.
 */

#ifndef TF_ATOMIC_H
#define TF_ATOMIC_H

#define tf_atomic_inc(var) \
	__sync_add_and_fetch(&(var), 1)
#define tf_atomic_dec(var) \
	__sync_add_and_fetch(&(var), -1)

#define tf_atomic_cmpxchg(ptr, old, new) \
	__sync_bool_compare_and_swap(ptr, old, new)
#define tf_atomic_xchg(ptr, new) \
	((typeof(*(ptr)))__sync_lock_test_and_set(ptr, new))

#endif