File: gbitlock.h

package info (click to toggle)
glib2.0 2.86.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 73,060 kB
  • sloc: ansic: 544,382; python: 9,702; sh: 1,612; xml: 1,482; perl: 1,222; cpp: 535; makefile: 321; javascript: 11
file content (120 lines) | stat: -rw-r--r-- 4,726 bytes parent folder | download | duplicates (3)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright © 2008 Ryan Lortie
 * Copyright © 2010 Codethink Limited
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Ryan Lortie <desrt@desrt.ca>
 */

#ifndef __G_BITLOCK_H__
#define __G_BITLOCK_H__

#include <glib/gtypes.h>

#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif

G_BEGIN_DECLS

GLIB_AVAILABLE_IN_ALL
void      g_bit_lock                      (volatile gint *address,
                                           gint           lock_bit);
GLIB_AVAILABLE_IN_2_86
void g_bit_lock_and_get (gint *address,
                         guint lock_bit,
                         gint *out_val);

GLIB_AVAILABLE_IN_ALL
gboolean  g_bit_trylock                   (volatile gint *address,
                                           gint           lock_bit);
GLIB_AVAILABLE_IN_ALL
void      g_bit_unlock                    (volatile gint *address,
                                           gint           lock_bit);

GLIB_AVAILABLE_IN_2_86
void g_bit_unlock_and_set (gint *address,
                           guint lock_bit,
                           gint new_val,
                           gint preserve_mask);

GLIB_AVAILABLE_IN_ALL
void      g_pointer_bit_lock              (volatile void *address,
                                           gint           lock_bit);

GLIB_AVAILABLE_IN_2_80
void      g_pointer_bit_lock_and_get      (gpointer address,
                                           guint lock_bit,
                                           guintptr *out_ptr);

GLIB_AVAILABLE_IN_ALL
gboolean  g_pointer_bit_trylock           (volatile void *address,
                                           gint           lock_bit);
GLIB_AVAILABLE_IN_ALL
void      g_pointer_bit_unlock            (volatile void *address,
                                           gint           lock_bit);

GLIB_AVAILABLE_IN_2_80
gpointer  g_pointer_bit_lock_mask_ptr     (gpointer ptr,
                                           guint lock_bit,
                                           gboolean set,
                                           guintptr preserve_mask,
                                           gpointer preserve_ptr);

GLIB_AVAILABLE_IN_2_80
void g_pointer_bit_unlock_and_set         (void *address,
                                           guint lock_bit,
                                           gpointer ptr,
                                           guintptr preserve_mask);

#ifdef __GNUC__

#define g_pointer_bit_lock(address, lock_bit) \
  (G_GNUC_EXTENSION ({                                                       \
    G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer));                \
    g_pointer_bit_lock ((address), (lock_bit));                              \
  }))

#define g_pointer_bit_lock_and_get(address, lock_bit, out_ptr)     \
  (G_GNUC_EXTENSION ({                                             \
    G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer));      \
    g_pointer_bit_lock_and_get ((address), (lock_bit), (out_ptr)); \
  }))

#define g_pointer_bit_trylock(address, lock_bit) \
  (G_GNUC_EXTENSION ({                                                       \
    G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer));                \
    g_pointer_bit_trylock ((address), (lock_bit));                           \
  }))

#define g_pointer_bit_unlock(address, lock_bit) \
  (G_GNUC_EXTENSION ({                                                       \
    G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer));                \
    g_pointer_bit_unlock ((address), (lock_bit));                            \
  }))

#define g_pointer_bit_unlock_and_set(address, lock_bit, ptr, preserve_mask)       \
  (G_GNUC_EXTENSION ({                                                            \
    G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer));                     \
    g_pointer_bit_unlock_and_set ((address), (lock_bit), (ptr), (preserve_mask)); \
  }))

#endif

G_END_DECLS

#endif /* __G_BITLOCK_H_ */