~ubuntu-branches/ubuntu/trusty/geis/trusty

« back to all changes in this revision

Viewing changes to libgeis/geis_atomic.h

  • Committer: Package Import Robot
  • Author(s): Chase Douglas
  • Date: 2012-07-30 08:51:42 UTC
  • Revision ID: package-import@ubuntu.com-20120730085142-jrc33ygjvt0ob1wl
Tags: upstream-2.2.11
ImportĀ upstreamĀ versionĀ 2.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file libgeis/geis_atomic.c
 
3
 * @brief Atomic operation helpers
 
4
 *
 
5
 * Copyright 2011 Canonical Ltd.
 
6
 *
 
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
 
10
 * later version.
 
11
 *
 
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
 
15
 * details.
 
16
 *
 
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
 
20
 */
 
21
#ifndef GEIS_ATOMIC_H_
 
22
#define GEIS_ATOMIC_H_
 
23
 
 
24
/**
 
25
 * An atomic value used for reference counting.
 
26
 */
 
27
typedef unsigned int GeisRefCount;
 
28
 
 
29
/**
 
30
 * Atomically increments a refcount.
 
31
 *
 
32
 * @param[in] refcount  A pointer to a refcount.
 
33
 */
 
34
static inline void
 
35
geis_atomic_ref(GeisRefCount *refcount)
 
36
{
 
37
  __sync_fetch_and_add(refcount, 1);
 
38
}
 
39
 
 
40
/**
 
41
 * Atomically decrements a refcount.
 
42
 *
 
43
 * @param[in] refcount  A pointer to a refcount.
 
44
 *
 
45
 * @returns the new reccount value.
 
46
 */
 
47
static inline GeisRefCount
 
48
geis_atomic_unref(GeisRefCount *refcount)
 
49
{
 
50
  return __sync_sub_and_fetch(refcount, 1);
 
51
}
 
52
 
 
53
#endif /* GEIS_ATOMIC_H_ */