File indexing completed on 2026-05-06 08:41:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef __GREFCOUNT_H__
0022 #define __GREFCOUNT_H__
0023
0024 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
0025 #error "Only <glib.h> can be included directly."
0026 #endif
0027
0028 #include <glib/gatomic.h>
0029 #include <glib/gtypes.h>
0030
0031 G_BEGIN_DECLS
0032
0033 GLIB_AVAILABLE_IN_2_58
0034 void g_ref_count_init (grefcount *rc);
0035 GLIB_AVAILABLE_IN_2_58
0036 void g_ref_count_inc (grefcount *rc);
0037 GLIB_AVAILABLE_IN_2_58
0038 gboolean g_ref_count_dec (grefcount *rc);
0039 GLIB_AVAILABLE_IN_2_58
0040 gboolean g_ref_count_compare (grefcount *rc,
0041 gint val);
0042
0043 GLIB_AVAILABLE_IN_2_58
0044 void g_atomic_ref_count_init (gatomicrefcount *arc);
0045 GLIB_AVAILABLE_IN_2_58
0046 void g_atomic_ref_count_inc (gatomicrefcount *arc);
0047 GLIB_AVAILABLE_IN_2_58
0048 gboolean g_atomic_ref_count_dec (gatomicrefcount *arc);
0049 GLIB_AVAILABLE_IN_2_58
0050 gboolean g_atomic_ref_count_compare (gatomicrefcount *arc,
0051 gint val);
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 #define G_REF_COUNT_INIT -1 \
0078 GLIB_AVAILABLE_MACRO_IN_2_78
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 #define G_ATOMIC_REF_COUNT_INIT 1 \
0105 GLIB_AVAILABLE_MACRO_IN_2_78
0106
0107
0108
0109
0110
0111 #if defined(__GNUC__) && defined(G_DISABLE_CHECKS)
0112
0113 # define g_ref_count_init(rc) \
0114 (G_GNUC_EXTENSION ({ \
0115 G_STATIC_ASSERT (sizeof *(rc) == sizeof (grefcount)); \
0116 (void) (0 ? *(rc) ^ *(rc) : 1); \
0117 *(rc) = -1; \
0118 }))
0119
0120 # define g_ref_count_inc(rc) \
0121 (G_GNUC_EXTENSION ({ \
0122 G_STATIC_ASSERT (sizeof *(rc) == sizeof (grefcount)); \
0123 (void) (0 ? *(rc) ^ *(rc) : 1); \
0124 if (*(rc) == G_MININT) ; else { \
0125 *(rc) -= 1; \
0126 } \
0127 }))
0128
0129 # define g_ref_count_dec(rc) \
0130 (G_GNUC_EXTENSION ({ \
0131 G_STATIC_ASSERT (sizeof *(rc) == sizeof (grefcount)); \
0132 grefcount __rc = *(rc); \
0133 __rc += 1; \
0134 if (__rc == 0) ; else { \
0135 *(rc) = __rc; \
0136 } \
0137 (gboolean) (__rc == 0); \
0138 }))
0139
0140 # define g_ref_count_compare(rc,val) \
0141 (G_GNUC_EXTENSION ({ \
0142 G_STATIC_ASSERT (sizeof *(rc) == sizeof (grefcount)); \
0143 (void) (0 ? *(rc) ^ (val) : 1); \
0144 (gboolean) (*(rc) == -(val)); \
0145 }))
0146
0147 # define g_atomic_ref_count_init(rc) \
0148 (G_GNUC_EXTENSION ({ \
0149 G_STATIC_ASSERT (sizeof *(rc) == sizeof (gatomicrefcount)); \
0150 (void) (0 ? *(rc) ^ *(rc) : 1); \
0151 *(rc) = 1; \
0152 }))
0153
0154 # define g_atomic_ref_count_inc(rc) \
0155 (G_GNUC_EXTENSION ({ \
0156 G_STATIC_ASSERT (sizeof *(rc) == sizeof (gatomicrefcount)); \
0157 (void) (0 ? *(rc) ^ *(rc) : 1); \
0158 (void) (g_atomic_int_get (rc) == G_MAXINT ? 0 : g_atomic_int_inc ((rc))); \
0159 }))
0160
0161 # define g_atomic_ref_count_dec(rc) \
0162 (G_GNUC_EXTENSION ({ \
0163 G_STATIC_ASSERT (sizeof *(rc) == sizeof (gatomicrefcount)); \
0164 (void) (0 ? *(rc) ^ *(rc) : 1); \
0165 g_atomic_int_dec_and_test ((rc)); \
0166 }))
0167
0168 # define g_atomic_ref_count_compare(rc,val) \
0169 (G_GNUC_EXTENSION ({ \
0170 G_STATIC_ASSERT (sizeof *(rc) == sizeof (gatomicrefcount)); \
0171 (void) (0 ? *(rc) ^ (val) : 1); \
0172 (gboolean) (g_atomic_int_get (rc) == (val)); \
0173 }))
0174
0175 #endif
0176
0177 G_END_DECLS
0178
0179 #endif