gbitlock.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 of the licence, 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. #ifndef __G_BITLOCK_H__
  21. #define __G_BITLOCK_H__
  22. #include <glib/gtypes.h>
  23. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  24. #error "Only <glib.h> can be included directly."
  25. #endif
  26. G_BEGIN_DECLS
  27. GLIB_AVAILABLE_IN_ALL
  28. void g_bit_lock (volatile gint *address,
  29. gint lock_bit);
  30. GLIB_AVAILABLE_IN_ALL
  31. gboolean g_bit_trylock (volatile gint *address,
  32. gint lock_bit);
  33. GLIB_AVAILABLE_IN_ALL
  34. void g_bit_unlock (volatile gint *address,
  35. gint lock_bit);
  36. GLIB_AVAILABLE_IN_ALL
  37. void g_pointer_bit_lock (volatile void *address,
  38. gint lock_bit);
  39. GLIB_AVAILABLE_IN_ALL
  40. gboolean g_pointer_bit_trylock (volatile void *address,
  41. gint lock_bit);
  42. GLIB_AVAILABLE_IN_ALL
  43. void g_pointer_bit_unlock (volatile void *address,
  44. gint lock_bit);
  45. #ifdef __GNUC__
  46. #define g_pointer_bit_lock(address, lock_bit) \
  47. (G_GNUC_EXTENSION ({ \
  48. G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
  49. g_pointer_bit_lock ((address), (lock_bit)); \
  50. }))
  51. #define g_pointer_bit_trylock(address, lock_bit) \
  52. (G_GNUC_EXTENSION ({ \
  53. G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
  54. g_pointer_bit_trylock ((address), (lock_bit)); \
  55. }))
  56. #define g_pointer_bit_unlock(address, lock_bit) \
  57. (G_GNUC_EXTENSION ({ \
  58. G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
  59. g_pointer_bit_unlock ((address), (lock_bit)); \
  60. }))
  61. #endif
  62. G_END_DECLS
  63. #endif /* __G_BITLOCK_H_ */