gbitlock.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright © 2008 Ryan Lortie
  3. * Copyright © 2010 Codethink Limited
  4. *
  5. * SPDX-License-Identifier: LGPL-2.1-or-later
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * Author: Ryan Lortie <desrt@desrt.ca>
  21. */
  22. #ifndef __G_BITLOCK_H__
  23. #define __G_BITLOCK_H__
  24. #include <glib/gtypes.h>
  25. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  26. #error "Only <glib.h> can be included directly."
  27. #endif
  28. G_BEGIN_DECLS
  29. GLIB_AVAILABLE_IN_ALL
  30. void g_bit_lock (volatile gint *address,
  31. gint lock_bit);
  32. GLIB_AVAILABLE_IN_ALL
  33. gboolean g_bit_trylock (volatile gint *address,
  34. gint lock_bit);
  35. GLIB_AVAILABLE_IN_ALL
  36. void g_bit_unlock (volatile gint *address,
  37. gint lock_bit);
  38. GLIB_AVAILABLE_IN_ALL
  39. void g_pointer_bit_lock (volatile void *address,
  40. gint lock_bit);
  41. GLIB_AVAILABLE_IN_2_80
  42. void g_pointer_bit_lock_and_get (gpointer address,
  43. guint lock_bit,
  44. guintptr *out_ptr);
  45. GLIB_AVAILABLE_IN_ALL
  46. gboolean g_pointer_bit_trylock (volatile void *address,
  47. gint lock_bit);
  48. GLIB_AVAILABLE_IN_ALL
  49. void g_pointer_bit_unlock (volatile void *address,
  50. gint lock_bit);
  51. GLIB_AVAILABLE_IN_2_80
  52. gpointer g_pointer_bit_lock_mask_ptr (gpointer ptr,
  53. guint lock_bit,
  54. gboolean set,
  55. guintptr preserve_mask,
  56. gpointer preserve_ptr);
  57. GLIB_AVAILABLE_IN_2_80
  58. void g_pointer_bit_unlock_and_set (void *address,
  59. guint lock_bit,
  60. gpointer ptr,
  61. guintptr preserve_mask);
  62. #ifdef __GNUC__
  63. #define g_pointer_bit_lock(address, lock_bit) \
  64. (G_GNUC_EXTENSION ({ \
  65. G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
  66. g_pointer_bit_lock ((address), (lock_bit)); \
  67. }))
  68. #define g_pointer_bit_lock_and_get(address, lock_bit, out_ptr) \
  69. (G_GNUC_EXTENSION ({ \
  70. G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
  71. g_pointer_bit_lock_and_get ((address), (lock_bit), (out_ptr)); \
  72. }))
  73. #define g_pointer_bit_trylock(address, lock_bit) \
  74. (G_GNUC_EXTENSION ({ \
  75. G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
  76. g_pointer_bit_trylock ((address), (lock_bit)); \
  77. }))
  78. #define g_pointer_bit_unlock(address, lock_bit) \
  79. (G_GNUC_EXTENSION ({ \
  80. G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
  81. g_pointer_bit_unlock ((address), (lock_bit)); \
  82. }))
  83. #define g_pointer_bit_unlock_and_set(address, lock_bit, ptr, preserve_mask) \
  84. (G_GNUC_EXTENSION ({ \
  85. G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
  86. g_pointer_bit_unlock_and_set ((address), (lock_bit), (ptr), (preserve_mask)); \
  87. }))
  88. #endif
  89. G_END_DECLS
  90. #endif /* __G_BITLOCK_H_ */