2
* @file libgeis/geis_atomic.c
3
* @brief Atomic operation helpers
5
* Copyright 2011 Canonical Ltd.
7
* This library is free software; you can redistribute it and/or modify it under
8
* the terms of the GNU Lesser General Public License as published by the Free
9
* Software Foundation; either version 3 of the License, or (at your option) any
12
* This library is distributed in the hope that it will be useful, but WITHOUT
13
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17
* You should have received a copy of the GNU Lesser General Public License
18
* along with this program; if not, write to the Free Software Foundation, Inc.,
19
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#ifndef GEIS_ATOMIC_H_
22
#define GEIS_ATOMIC_H_
25
* An atomic value used for reference counting.
27
typedef unsigned int GeisRefCount;
30
* Atomically increments a refcount.
32
* @param[in] refcount A pointer to a refcount.
35
geis_atomic_ref(GeisRefCount *refcount)
37
__sync_fetch_and_add(refcount, 1);
41
* Atomically decrements a refcount.
43
* @param[in] refcount A pointer to a refcount.
45
* @returns the new reccount value.
47
static inline GeisRefCount
48
geis_atomic_unref(GeisRefCount *refcount)
50
return __sync_sub_and_fetch(refcount, 1);
53
#endif /* GEIS_ATOMIC_H_ */