Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

106 Zeilen
4.1 KiB

  1. /* GLIB - Library of useful routines for C programming
  2. * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  3. *
  4. * g_atomic_*: atomic operations.
  5. * Copyright (C) 2003 Sebastian Wilhelmi
  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 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, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. */
  22. /*
  23. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  24. * file for a list of people on the GLib Team. See the ChangeLog
  25. * files for a list of changes. These files are distributed with
  26. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  27. */
  28. #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  29. #error "Only <glib.h> can be included directly."
  30. #endif
  31. #ifndef __G_ATOMIC_H__
  32. #define __G_ATOMIC_H__
  33. #include <glib/gtypes.h>
  34. G_BEGIN_DECLS
  35. gint g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
  36. gint val);
  37. void g_atomic_int_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
  38. gint val);
  39. gboolean g_atomic_int_compare_and_exchange (volatile gint G_GNUC_MAY_ALIAS *atomic,
  40. gint oldval,
  41. gint newval);
  42. gboolean g_atomic_pointer_compare_and_exchange (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
  43. gpointer oldval,
  44. gpointer newval);
  45. gint g_atomic_int_get (volatile gint G_GNUC_MAY_ALIAS *atomic);
  46. void g_atomic_int_set (volatile gint G_GNUC_MAY_ALIAS *atomic,
  47. gint newval);
  48. gpointer g_atomic_pointer_get (volatile gpointer G_GNUC_MAY_ALIAS *atomic);
  49. void g_atomic_pointer_set (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
  50. gpointer newval);
  51. #ifndef G_ATOMIC_OP_MEMORY_BARRIER_NEEDED
  52. # define g_atomic_int_get(atomic) ((gint)*(atomic))
  53. # define g_atomic_int_set(atomic, newval) ((void) (*(atomic) = (newval)))
  54. # define g_atomic_pointer_get(atomic) ((gpointer)*(atomic))
  55. # define g_atomic_pointer_set(atomic, newval) ((void) (*(atomic) = (newval)))
  56. #else
  57. # define g_atomic_int_get(atomic) \
  58. ((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gint) ? 1 : -1]), \
  59. (g_atomic_int_get) ((volatile gint G_GNUC_MAY_ALIAS *) (volatile void *) (atomic)))
  60. # define g_atomic_int_set(atomic, newval) \
  61. ((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gint) ? 1 : -1]), \
  62. (g_atomic_int_set) ((volatile gint G_GNUC_MAY_ALIAS *) (volatile void *) (atomic), (newval)))
  63. # define g_atomic_pointer_get(atomic) \
  64. ((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gpointer) ? 1 : -1]), \
  65. (g_atomic_pointer_get) ((volatile gpointer G_GNUC_MAY_ALIAS *) (volatile void *) (atomic)))
  66. # define g_atomic_pointer_set(atomic, newval) \
  67. ((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gpointer) ? 1 : -1]), \
  68. (g_atomic_pointer_set) ((volatile gpointer G_GNUC_MAY_ALIAS *) (volatile void *) (atomic), (newval)))
  69. #endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */
  70. /**
  71. * g_atomic_int_inc:
  72. * @atomic: a pointer to an integer.
  73. *
  74. * Atomically increments the integer pointed to by @atomic by 1.
  75. *
  76. * Since: 2.4
  77. */
  78. #define g_atomic_int_inc(atomic) (g_atomic_int_add ((atomic), 1))
  79. /**
  80. * g_atomic_int_dec_and_test:
  81. * @atomic: a pointer to an integer
  82. *
  83. * Atomically decrements the integer pointed to by @atomic by 1.
  84. *
  85. * Returns: %TRUE if the integer pointed to by @atomic is 0
  86. * after decrementing it
  87. *
  88. * Since: 2.4
  89. */
  90. #define g_atomic_int_dec_and_test(atomic) \
  91. (g_atomic_int_exchange_and_add ((atomic), -1) == 1)
  92. G_END_DECLS
  93. #endif /* __G_ATOMIC_H__ */