gbitlock.h 2.83 KB
Newer Older
1 2 3 4 5 6 7
/*
 * Copyright © 2008 Ryan Lortie
 * Copyright © 2010 Codethink Limited
 *
 * 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
8
 * version 2.1 of the License, or (at your option) any later version.
9 10 11 12 13 14 15
 *
 * 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
16
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 18 19 20 21 22 23 24 25
 *
 * Author: Ryan Lortie <desrt@desrt.ca>
 */

#ifndef __G_BITLOCK_H__
#define __G_BITLOCK_H__

#include <glib/gtypes.h>

26
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
27 28 29 30 31
#error "Only <glib.h> can be included directly."
#endif

G_BEGIN_DECLS

32
GLIB_AVAILABLE_IN_ALL
33
void      g_bit_lock                      (volatile gint *address,
34
                                           gint           lock_bit);
35
GLIB_AVAILABLE_IN_ALL
36
gboolean  g_bit_trylock                   (volatile gint *address,
37
                                           gint           lock_bit);
38
GLIB_AVAILABLE_IN_ALL
39
void      g_bit_unlock                    (volatile gint *address,
40 41
                                           gint           lock_bit);

42
GLIB_AVAILABLE_IN_ALL
43 44
void      g_pointer_bit_lock              (volatile void *address,
                                           gint           lock_bit);
45
GLIB_AVAILABLE_IN_ALL
46 47
gboolean  g_pointer_bit_trylock           (volatile void *address,
                                           gint           lock_bit);
48
GLIB_AVAILABLE_IN_ALL
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
void      g_pointer_bit_unlock            (volatile void *address,
                                           gint           lock_bit);

#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_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));                            \
  }))

#endif

74 75 76
G_END_DECLS

#endif /* __G_BITLOCK_H_ */