/* atomic.h - wrapper for atomic gcc built-ins * * Copyright (C) 2009 Timo Teräs * 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