1/*
2 * Copyright © 2008 Ryan Lortie
3 * Copyright © 2010 Codethink Limited
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, see <http://www.gnu.org/licenses/>.
17 *
18 * Author: Ryan Lortie <desrt@desrt.ca>
19 */
20
21#ifndef __G_BITLOCK_H__
22#define __G_BITLOCK_H__
23
24#include <glib/gtypes.h>
25
26#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
27#error "Only <glib.h> can be included directly."
28#endif
29
30G_BEGIN_DECLS
31
32GLIB_AVAILABLE_IN_ALL
33void g_bit_lock (volatile gint *address,
34 gint lock_bit);
35GLIB_AVAILABLE_IN_ALL
36gboolean g_bit_trylock (volatile gint *address,
37 gint lock_bit);
38GLIB_AVAILABLE_IN_ALL
39void g_bit_unlock (volatile gint *address,
40 gint lock_bit);
41
42GLIB_AVAILABLE_IN_ALL
43void g_pointer_bit_lock (volatile void *address,
44 gint lock_bit);
45GLIB_AVAILABLE_IN_ALL
46gboolean g_pointer_bit_trylock (volatile void *address,
47 gint lock_bit);
48GLIB_AVAILABLE_IN_ALL
49void g_pointer_bit_unlock (volatile void *address,
50 gint lock_bit);
51
52#ifdef __GNUC__
53
54#define g_pointer_bit_lock(address, lock_bit) \
55 (G_GNUC_EXTENSION ({ \
56 G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
57 g_pointer_bit_lock ((address), (lock_bit)); \
58 }))
59
60#define g_pointer_bit_trylock(address, lock_bit) \
61 (G_GNUC_EXTENSION ({ \
62 G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
63 g_pointer_bit_trylock ((address), (lock_bit)); \
64 }))
65
66#define g_pointer_bit_unlock(address, lock_bit) \
67 (G_GNUC_EXTENSION ({ \
68 G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
69 g_pointer_bit_unlock ((address), (lock_bit)); \
70 }))
71
72#endif
73
74G_END_DECLS
75
76#endif /* __G_BITLOCK_H_ */
77

source code of include/glib-2.0/glib/gbitlock.h