Update Changelog
[profile/ivi/libgee.git] / gee / hazardpointer.c
1 /* hazardpointer.c generated by valac 0.18.0, the Vala compiler
2  * generated from hazardpointer.vala, do not modify */
3
4 /* hazardpointer.vala
5  *
6  * Copyright (C) 2011  Maciej Piechotka
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
21  *
22  * Author:
23  *      Maciej Piechotka <uzytkownik2@gmail.com>
24  */
25
26 #include <glib.h>
27 #include <glib-object.h>
28 #include <string.h>
29
30 typedef struct _GeeHazardPointer GeeHazardPointer;
31 typedef struct _GeeHazardPointerNode GeeHazardPointerNode;
32
33 #define GEE_HAZARD_POINTER_TYPE_POLICY (gee_hazard_pointer_policy_get_type ())
34
35 #define GEE_TYPE_ABSTRACT_COLLECTION (gee_abstract_collection_get_type ())
36 #define GEE_ABSTRACT_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollection))
37 #define GEE_ABSTRACT_COLLECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollectionClass))
38 #define GEE_IS_ABSTRACT_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ABSTRACT_COLLECTION))
39 #define GEE_IS_ABSTRACT_COLLECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_ABSTRACT_COLLECTION))
40 #define GEE_ABSTRACT_COLLECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_ABSTRACT_COLLECTION, GeeAbstractCollectionClass))
41
42 typedef struct _GeeAbstractCollection GeeAbstractCollection;
43 typedef struct _GeeAbstractCollectionClass GeeAbstractCollectionClass;
44
45 #define GEE_TYPE_ABSTRACT_LIST (gee_abstract_list_get_type ())
46 #define GEE_ABSTRACT_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ABSTRACT_LIST, GeeAbstractList))
47 #define GEE_ABSTRACT_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_ABSTRACT_LIST, GeeAbstractListClass))
48 #define GEE_IS_ABSTRACT_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ABSTRACT_LIST))
49 #define GEE_IS_ABSTRACT_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_ABSTRACT_LIST))
50 #define GEE_ABSTRACT_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_ABSTRACT_LIST, GeeAbstractListClass))
51
52 typedef struct _GeeAbstractList GeeAbstractList;
53 typedef struct _GeeAbstractListClass GeeAbstractListClass;
54
55 #define GEE_TYPE_ABSTRACT_BIDIR_LIST (gee_abstract_bidir_list_get_type ())
56 #define GEE_ABSTRACT_BIDIR_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ABSTRACT_BIDIR_LIST, GeeAbstractBidirList))
57 #define GEE_ABSTRACT_BIDIR_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_ABSTRACT_BIDIR_LIST, GeeAbstractBidirListClass))
58 #define GEE_IS_ABSTRACT_BIDIR_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ABSTRACT_BIDIR_LIST))
59 #define GEE_IS_ABSTRACT_BIDIR_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_ABSTRACT_BIDIR_LIST))
60 #define GEE_ABSTRACT_BIDIR_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_ABSTRACT_BIDIR_LIST, GeeAbstractBidirListClass))
61
62 typedef struct _GeeAbstractBidirList GeeAbstractBidirList;
63 typedef struct _GeeAbstractBidirListClass GeeAbstractBidirListClass;
64
65 #define GEE_TYPE_ARRAY_LIST (gee_array_list_get_type ())
66 #define GEE_ARRAY_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ARRAY_LIST, GeeArrayList))
67 #define GEE_ARRAY_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_ARRAY_LIST, GeeArrayListClass))
68 #define GEE_IS_ARRAY_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ARRAY_LIST))
69 #define GEE_IS_ARRAY_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_ARRAY_LIST))
70 #define GEE_ARRAY_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_ARRAY_LIST, GeeArrayListClass))
71
72 typedef struct _GeeArrayList GeeArrayList;
73 typedef struct _GeeArrayListClass GeeArrayListClass;
74 typedef struct _GeeHazardPointerFreeNode GeeHazardPointerFreeNode;
75 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
76
77 #define GEE_TYPE_TRAVERSABLE (gee_traversable_get_type ())
78 #define GEE_TRAVERSABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_TRAVERSABLE, GeeTraversable))
79 #define GEE_IS_TRAVERSABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_TRAVERSABLE))
80 #define GEE_TRAVERSABLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_TRAVERSABLE, GeeTraversableIface))
81
82 typedef struct _GeeTraversable GeeTraversable;
83 typedef struct _GeeTraversableIface GeeTraversableIface;
84
85 #define GEE_TRAVERSABLE_TYPE_STREAM (gee_traversable_stream_get_type ())
86
87 #define GEE_TYPE_LAZY (gee_lazy_get_type ())
88 #define GEE_LAZY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_LAZY, GeeLazy))
89 #define GEE_LAZY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_LAZY, GeeLazyClass))
90 #define GEE_IS_LAZY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_LAZY))
91 #define GEE_IS_LAZY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_LAZY))
92 #define GEE_LAZY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_LAZY, GeeLazyClass))
93
94 typedef struct _GeeLazy GeeLazy;
95 typedef struct _GeeLazyClass GeeLazyClass;
96
97 #define GEE_TYPE_ITERATOR (gee_iterator_get_type ())
98 #define GEE_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ITERATOR, GeeIterator))
99 #define GEE_IS_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ITERATOR))
100 #define GEE_ITERATOR_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_ITERATOR, GeeIteratorIface))
101
102 typedef struct _GeeIterator GeeIterator;
103 typedef struct _GeeIteratorIface GeeIteratorIface;
104
105 #define GEE_TYPE_ITERABLE (gee_iterable_get_type ())
106 #define GEE_ITERABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ITERABLE, GeeIterable))
107 #define GEE_IS_ITERABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ITERABLE))
108 #define GEE_ITERABLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_ITERABLE, GeeIterableIface))
109
110 typedef struct _GeeIterable GeeIterable;
111 typedef struct _GeeIterableIface GeeIterableIface;
112
113 #define GEE_TYPE_COLLECTION (gee_collection_get_type ())
114 #define GEE_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_COLLECTION, GeeCollection))
115 #define GEE_IS_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_COLLECTION))
116 #define GEE_COLLECTION_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_COLLECTION, GeeCollectionIface))
117
118 typedef struct _GeeCollection GeeCollection;
119 typedef struct _GeeCollectionIface GeeCollectionIface;
120
121 #define GEE_TYPE_QUEUE (gee_queue_get_type ())
122 #define GEE_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_QUEUE, GeeQueue))
123 #define GEE_IS_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_QUEUE))
124 #define GEE_QUEUE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_QUEUE, GeeQueueIface))
125
126 typedef struct _GeeQueue GeeQueue;
127 typedef struct _GeeQueueIface GeeQueueIface;
128
129 #define GEE_HAZARD_POINTER_TYPE_RELEASE_POLICY (gee_hazard_pointer_release_policy_get_type ())
130
131 #define GEE_TYPE_LINKED_LIST (gee_linked_list_get_type ())
132 #define GEE_LINKED_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_LINKED_LIST, GeeLinkedList))
133 #define GEE_LINKED_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_LINKED_LIST, GeeLinkedListClass))
134 #define GEE_IS_LINKED_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_LINKED_LIST))
135 #define GEE_IS_LINKED_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_LINKED_LIST))
136 #define GEE_LINKED_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_LINKED_LIST, GeeLinkedListClass))
137
138 typedef struct _GeeLinkedList GeeLinkedList;
139 typedef struct _GeeLinkedListClass GeeLinkedListClass;
140 #define _g_destroy_func0(var) (((var == NULL) || (g_destroy_func == NULL)) ? NULL : (var = (g_destroy_func (var), NULL)))
141 #define _gee_hazard_pointer_free0(var) ((var == NULL) ? NULL : (var = (gee_hazard_pointer_free (var), NULL)))
142 typedef struct _GeeHazardPointerContext GeeHazardPointerContext;
143
144 #define GEE_TYPE_ABSTRACT_SET (gee_abstract_set_get_type ())
145 #define GEE_ABSTRACT_SET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_ABSTRACT_SET, GeeAbstractSet))
146 #define GEE_ABSTRACT_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_ABSTRACT_SET, GeeAbstractSetClass))
147 #define GEE_IS_ABSTRACT_SET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_ABSTRACT_SET))
148 #define GEE_IS_ABSTRACT_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_ABSTRACT_SET))
149 #define GEE_ABSTRACT_SET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_ABSTRACT_SET, GeeAbstractSetClass))
150
151 typedef struct _GeeAbstractSet GeeAbstractSet;
152 typedef struct _GeeAbstractSetClass GeeAbstractSetClass;
153
154 #define GEE_TYPE_HASH_SET (gee_hash_set_get_type ())
155 #define GEE_HASH_SET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_HASH_SET, GeeHashSet))
156 #define GEE_HASH_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_HASH_SET, GeeHashSetClass))
157 #define GEE_IS_HASH_SET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_HASH_SET))
158 #define GEE_IS_HASH_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_HASH_SET))
159 #define GEE_HASH_SET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_HASH_SET, GeeHashSetClass))
160
161 typedef struct _GeeHashSet GeeHashSet;
162 typedef struct _GeeHashSetClass GeeHashSetClass;
163 typedef struct _Block5Data Block5Data;
164 #define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
165 #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
166
167 struct _GeeHazardPointer {
168         GeeHazardPointerNode* _node;
169 };
170
171 typedef enum  {
172         GEE_HAZARD_POINTER_POLICY_DEFAULT,
173         GEE_HAZARD_POINTER_POLICY_THREAD_EXIT,
174         GEE_HAZARD_POINTER_POLICY_TRY_FREE,
175         GEE_HAZARD_POINTER_POLICY_FREE,
176         GEE_HAZARD_POINTER_POLICY_TRY_RELEASE,
177         GEE_HAZARD_POINTER_POLICY_RELEASE
178 } GeeHazardPointerPolicy;
179
180 typedef gboolean (*GeeForallFunc) (gpointer g, void* user_data);
181 typedef enum  {
182         GEE_TRAVERSABLE_STREAM_YIELD,
183         GEE_TRAVERSABLE_STREAM_CONTINUE,
184         GEE_TRAVERSABLE_STREAM_END
185 } GeeTraversableStream;
186
187 typedef GeeTraversableStream (*GeeStreamFunc) (GeeTraversableStream state, GeeLazy* g, GeeLazy** lazy, void* user_data);
188 struct _GeeIteratorIface {
189         GTypeInterface parent_iface;
190         gboolean (*next) (GeeIterator* self);
191         gboolean (*has_next) (GeeIterator* self);
192         gpointer (*get) (GeeIterator* self);
193         void (*remove) (GeeIterator* self);
194         gboolean (*get_valid) (GeeIterator* self);
195         gboolean (*get_read_only) (GeeIterator* self);
196 };
197
198 typedef gpointer (*GeeFoldFunc) (gpointer g, gpointer a, void* user_data);
199 typedef gpointer (*GeeMapFunc) (gpointer g, void* user_data);
200 typedef gboolean (*GeePredicate) (gconstpointer g, void* user_data);
201 struct _GeeTraversableIface {
202         GTypeInterface parent_iface;
203         GType (*get_g_type) (GeeTraversable* self);
204         GBoxedCopyFunc (*get_g_dup_func) (GeeTraversable* self);
205         GDestroyNotify (*get_g_destroy_func) (GeeTraversable* self);
206         gboolean (*foreach) (GeeTraversable* self, GeeForallFunc f, void* f_target);
207         GeeIterator* (*stream) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeStreamFunc f, void* f_target, GDestroyNotify f_target_destroy_notify);
208         gpointer (*fold) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldFunc f, void* f_target, gpointer seed);
209         GeeIterator* (*map) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeMapFunc f, void* f_target);
210         GeeIterator* (*scan) (GeeTraversable* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldFunc f, void* f_target, gpointer seed);
211         GeeIterator* (*filter) (GeeTraversable* self, GeePredicate pred, void* pred_target, GDestroyNotify pred_target_destroy_notify);
212         GeeIterator* (*chop) (GeeTraversable* self, gint offset, gint length);
213         GType (*get_element_type) (GeeTraversable* self);
214 };
215
216 struct _GeeIterableIface {
217         GTypeInterface parent_iface;
218         GType (*get_g_type) (GeeIterable* self);
219         GBoxedCopyFunc (*get_g_dup_func) (GeeIterable* self);
220         GDestroyNotify (*get_g_destroy_func) (GeeIterable* self);
221         GeeIterator* (*iterator) (GeeIterable* self);
222 };
223
224 struct _GeeCollectionIface {
225         GTypeInterface parent_iface;
226         GType (*get_g_type) (GeeCollection* self);
227         GBoxedCopyFunc (*get_g_dup_func) (GeeCollection* self);
228         GDestroyNotify (*get_g_destroy_func) (GeeCollection* self);
229         gboolean (*contains) (GeeCollection* self, gconstpointer item);
230         gboolean (*add) (GeeCollection* self, gconstpointer item);
231         gboolean (*remove) (GeeCollection* self, gconstpointer item);
232         void (*clear) (GeeCollection* self);
233         gboolean (*add_all) (GeeCollection* self, GeeCollection* collection);
234         gboolean (*contains_all) (GeeCollection* self, GeeCollection* collection);
235         gboolean (*remove_all) (GeeCollection* self, GeeCollection* collection);
236         gboolean (*retain_all) (GeeCollection* self, GeeCollection* collection);
237         gpointer* (*to_array) (GeeCollection* self, int* result_length1);
238         gint (*get_size) (GeeCollection* self);
239         gboolean (*get_is_empty) (GeeCollection* self);
240         gboolean (*get_read_only) (GeeCollection* self);
241         GeeCollection* (*get_read_only_view) (GeeCollection* self);
242 };
243
244 struct _GeeQueueIface {
245         GTypeInterface parent_iface;
246         GType (*get_g_type) (GeeQueue* self);
247         GBoxedCopyFunc (*get_g_dup_func) (GeeQueue* self);
248         GDestroyNotify (*get_g_destroy_func) (GeeQueue* self);
249         gboolean (*offer) (GeeQueue* self, gconstpointer element);
250         gpointer (*peek) (GeeQueue* self);
251         gpointer (*poll) (GeeQueue* self);
252         gint (*drain) (GeeQueue* self, GeeCollection* recipient, gint amount);
253         gint (*get_capacity) (GeeQueue* self);
254         gint (*get_remaining_capacity) (GeeQueue* self);
255         gboolean (*get_is_full) (GeeQueue* self);
256 };
257
258 typedef enum  {
259         GEE_HAZARD_POINTER_RELEASE_POLICY_HELPER_THREAD,
260         GEE_HAZARD_POINTER_RELEASE_POLICY_MAIN_LOOP
261 } GeeHazardPointerReleasePolicy;
262
263 typedef gboolean (*GeeEqualDataFunc) (gconstpointer a, gconstpointer b, void* user_data);
264 typedef void (*GeeHazardPointerDestroyNotify) (void* ptr, void* user_data);
265 typedef guint (*GeeHashDataFunc) (gconstpointer v, void* user_data);
266 struct _GeeHazardPointerFreeNode {
267         void* pointer;
268         GeeHazardPointerDestroyNotify destroy_notify;
269         gpointer destroy_notify_target;
270         GDestroyNotify destroy_notify_target_destroy_notify;
271 };
272
273 struct _Block5Data {
274         int _ref_count_;
275         GType g_type;
276         GBoxedCopyFunc g_dup_func;
277         GDestroyNotify g_destroy_func;
278 };
279
280 struct _GeeHazardPointerContext {
281         GeeHazardPointerContext* _parent;
282         GeeArrayList* _to_free;
283         GeeHazardPointerPolicy* _policy;
284 };
285
286 struct _GeeHazardPointerNode {
287         GeeHazardPointerNode* _next;
288         gint _active;
289         void* _hazard;
290 };
291
292
293 extern gint gee_hazard_pointer__default_policy;
294 extern gint gee_hazard_pointer__thread_exit_policy;
295 extern GStaticMutex gee_hazard_pointer__queue_mutex;
296 extern GeeQueue* gee_hazard_pointer__queue;
297 extern gint gee_hazard_pointer_release_policy;
298 extern GeeArrayList* gee_hazard_pointer__global_to_free;
299 extern GeeHazardPointerNode* gee_hazard_pointer__head;
300 GeeHazardPointerNode* gee_hazard_pointer__head = NULL;
301 gint gee_hazard_pointer__default_policy = (gint) GEE_HAZARD_POINTER_POLICY_TRY_FREE;
302 gint gee_hazard_pointer__thread_exit_policy = (gint) GEE_HAZARD_POINTER_POLICY_RELEASE;
303 gint gee_hazard_pointer_release_policy = 0;
304 GeeQueue* gee_hazard_pointer__queue = NULL;
305 GStaticMutex gee_hazard_pointer__queue_mutex = G_STATIC_MUTEX_INIT;
306 GeeArrayList* gee_hazard_pointer__global_to_free = NULL;
307 static guint gee_hazard_pointer_context_THRESHOLD;
308 extern GStaticPrivate gee_hazard_pointer_context__current_context;
309 GStaticPrivate gee_hazard_pointer_context__current_context = G_STATIC_PRIVATE_INIT;
310 extern GStaticPrivate gee_hazard_pointer_context__root_context;
311 GStaticPrivate gee_hazard_pointer_context__root_context = G_STATIC_PRIVATE_INIT;
312 static guint gee_hazard_pointer_context_THRESHOLD = (guint) 10;
313
314 void gee_hazard_pointer_free (GeeHazardPointer* self);
315 void gee_hazard_pointer_node_free (GeeHazardPointerNode* self);
316 static void gee_hazard_pointer_instance_init (GeeHazardPointer * self);
317 void gee_hazard_pointer_node_release (GeeHazardPointerNode* self);
318 GType gee_hazard_pointer_policy_get_type (void) G_GNUC_CONST;
319 gboolean gee_hazard_pointer_policy_is_concrete (GeeHazardPointerPolicy self);
320 gboolean gee_hazard_pointer_policy_is_blocking (GeeHazardPointerPolicy self);
321 gboolean gee_hazard_pointer_policy_is_safe (GeeHazardPointerPolicy self);
322 GeeHazardPointerPolicy gee_hazard_pointer_policy_to_concrete (GeeHazardPointerPolicy self);
323 GType gee_abstract_collection_get_type (void) G_GNUC_CONST;
324 GType gee_abstract_list_get_type (void) G_GNUC_CONST;
325 GType gee_abstract_bidir_list_get_type (void) G_GNUC_CONST;
326 GType gee_array_list_get_type (void) G_GNUC_CONST;
327 void gee_hazard_pointer_free_node_free (GeeHazardPointerFreeNode* self);
328 GeeArrayList* gee_hazard_pointer_policy_perform (GeeHazardPointerPolicy self, GeeArrayList* to_free);
329 gboolean gee_hazard_pointer_try_free (GeeArrayList* to_free);
330 void gee_hazard_pointer_release_policy_ensure_start (void);
331 GType gee_traversable_stream_get_type (void) G_GNUC_CONST;
332 gpointer gee_lazy_ref (gpointer instance);
333 void gee_lazy_unref (gpointer instance);
334 GParamSpec* gee_param_spec_lazy (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
335 void gee_value_set_lazy (GValue* value, gpointer v_object);
336 void gee_value_take_lazy (GValue* value, gpointer v_object);
337 gpointer gee_value_get_lazy (const GValue* value);
338 GType gee_lazy_get_type (void) G_GNUC_CONST;
339 GType gee_iterator_get_type (void) G_GNUC_CONST;
340 GType gee_traversable_get_type (void) G_GNUC_CONST;
341 GType gee_iterable_get_type (void) G_GNUC_CONST;
342 GType gee_collection_get_type (void) G_GNUC_CONST;
343 GType gee_queue_get_type (void) G_GNUC_CONST;
344 gboolean gee_queue_offer (GeeQueue* self, gconstpointer element);
345 GType gee_hazard_pointer_release_policy_get_type (void) G_GNUC_CONST;
346 static void gee_hazard_pointer_release_policy_start (GeeHazardPointerReleasePolicy _self_);
347 static gboolean ___lambda33_ (void);
348 static inline void gee_hazard_pointer_release_policy_attempt_free (void);
349 static gpointer ____lambda33__gthread_func (gpointer self);
350 static gboolean ___lambda35_ (void);
351 static gboolean ____lambda35__gsource_func (gpointer self);
352 GeeLinkedList* gee_linked_list_new (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeEqualDataFunc equal_func, void* equal_func_target, GDestroyNotify equal_func_target_destroy_notify);
353 GeeLinkedList* gee_linked_list_construct (GType object_type, GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeEqualDataFunc equal_func, void* equal_func_target, GDestroyNotify equal_func_target_destroy_notify);
354 GType gee_linked_list_get_type (void) G_GNUC_CONST;
355 GeeArrayList* gee_array_list_new (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeEqualDataFunc equal_func, void* equal_func_target, GDestroyNotify equal_func_target_destroy_notify);
356 GeeArrayList* gee_array_list_construct (GType object_type, GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeEqualDataFunc equal_func, void* equal_func_target, GDestroyNotify equal_func_target_destroy_notify);
357 gint gee_queue_drain (GeeQueue* self, GeeCollection* recipient, gint amount);
358 gboolean gee_traversable_foreach (GeeTraversable* self, GeeForallFunc f, void* f_target);
359 static gboolean ___lambda34_ (GeeArrayList* x);
360 gboolean gee_array_list_add_all (GeeArrayList* self, GeeCollection* collection);
361 static gboolean ____lambda34__gee_forall_func (gpointer g, gpointer self);
362 GeeHazardPointer* gee_hazard_pointer_new (gconstpointer* ptr);
363 GeeHazardPointer* gee_hazard_pointer_new (gconstpointer* ptr);
364 GeeHazardPointerNode* gee_hazard_pointer_acquire (void);
365 void gee_hazard_pointer_node_set (GeeHazardPointerNode* self, void* ptr);
366 GeeHazardPointer* gee_hazard_pointer_new_from_node (GeeHazardPointerNode* node);
367 GeeHazardPointer* gee_hazard_pointer_new_from_node (GeeHazardPointerNode* node);
368 GeeHazardPointer* gee_hazard_pointer_get_hazard_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gsize mask, gsize* mask_out);
369 gpointer gee_hazard_pointer_get_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gsize mask, gsize* mask_out);
370 GeeHazardPointer* gee_hazard_pointer_exchange_hazard_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gpointer new_ptr, gsize mask, gsize new_mask, gsize* old_mask);
371 void gee_hazard_pointer_set_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gpointer new_ptr, gsize mask, gsize new_mask);
372 GeeHazardPointerDestroyNotify gee_hazard_pointer_get_destroy_notify (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, void** result_target, GDestroyNotify* result_target_destroy_notify);
373 void gee_hazard_pointer_release (GeeHazardPointer* self, GeeHazardPointerDestroyNotify notify, void* notify_target, GDestroyNotify notify_target_destroy_notify);
374 gpointer gee_hazard_pointer_exchange_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gpointer new_ptr, gsize mask, gsize new_mask, gsize* old_mask);
375 gconstpointer gee_hazard_pointer_get (GeeHazardPointer* self, gboolean other_thread);
376 gboolean gee_hazard_pointer_compare_and_exchange_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gconstpointer old_ptr, gpointer _new_ptr, gsize mask, gsize old_mask, gsize new_mask);
377 void gee_hazard_pointer_context_free (GeeHazardPointerContext* self);
378 GeeHazardPointerContext* gee_hazard_pointer_context_get_current_context (void);
379 void gee_hazard_pointer_context_release_ptr (GeeHazardPointerContext* self, void* ptr, GeeHazardPointerDestroyNotify notify, void* notify_target, GDestroyNotify notify_target_destroy_notify);
380 void* gee_hazard_pointer_node_get (GeeHazardPointerNode* self, gboolean safe);
381 void gee_hazard_pointer_set_default_policy (GeeHazardPointerPolicy policy);
382 void gee_hazard_pointer_set_thread_exit_policy (GeeHazardPointerPolicy policy);
383 gboolean gee_hazard_pointer_set_release_policy (GeeHazardPointerReleasePolicy policy);
384 GeeHazardPointerNode* gee_hazard_pointer_get_head (void);
385 GeeHazardPointerNode* gee_hazard_pointer_node_get_next (GeeHazardPointerNode* self);
386 gboolean gee_hazard_pointer_node_activate (GeeHazardPointerNode* self);
387 GeeHazardPointerNode* gee_hazard_pointer_node_new (void);
388 GeeHazardPointerNode* gee_hazard_pointer_node_new (void);
389 void gee_hazard_pointer_node_set_next (GeeHazardPointerNode* self, GeeHazardPointerNode* next);
390 GeeHashSet* gee_hash_set_new (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeHashDataFunc hash_func, void* hash_func_target, GDestroyNotify hash_func_target_destroy_notify, GeeEqualDataFunc equal_func, void* equal_func_target, GDestroyNotify equal_func_target_destroy_notify);
391 GeeHashSet* gee_hash_set_construct (GType object_type, GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeHashDataFunc hash_func, void* hash_func_target, GDestroyNotify hash_func_target_destroy_notify, GeeEqualDataFunc equal_func, void* equal_func_target, GDestroyNotify equal_func_target_destroy_notify);
392 GType gee_abstract_set_get_type (void) G_GNUC_CONST;
393 GType gee_hash_set_get_type (void) G_GNUC_CONST;
394 gboolean gee_collection_add (GeeCollection* self, gconstpointer item);
395 gint gee_abstract_collection_get_size (GeeAbstractCollection* self);
396 gpointer gee_abstract_list_get (GeeAbstractList* self, gint index);
397 gboolean gee_collection_contains (GeeCollection* self, gconstpointer item);
398 gpointer gee_abstract_list_remove_at (GeeAbstractList* self, gint index);
399 void gee_abstract_list_set (GeeAbstractList* self, gint index, gconstpointer item);
400 static Block5Data* block5_data_ref (Block5Data* _data5_);
401 static void block5_data_unref (void * _userdata_);
402 static void __lambda36_ (Block5Data* _data5_, void* ptr);
403 static void ___lambda36__gee_hazard_pointer_destroy_notify (void* ptr, gpointer self);
404 static void gee_hazard_pointer_context_instance_init (GeeHazardPointerContext * self);
405 GeeHazardPointerContext* gee_hazard_pointer_context_new (GeeHazardPointerPolicy* policy);
406 GeeHazardPointerContext* gee_hazard_pointer_context_new (GeeHazardPointerPolicy* policy);
407 static GeeHazardPointerPolicy* _gee_hazard_pointer_policy_dup (GeeHazardPointerPolicy* self);
408 void gee_hazard_pointer_context_try_free (GeeHazardPointerContext* self);
409 void gee_hazard_pointer_context_free_all (GeeHazardPointerContext* self);
410 void gee_hazard_pointer_context_try_release (GeeHazardPointerContext* self);
411 void gee_hazard_pointer_context_release (GeeHazardPointerContext* self);
412 GeeHazardPointerFreeNode* gee_hazard_pointer_free_node_new (void);
413 GeeHazardPointerFreeNode* gee_hazard_pointer_free_node_new (void);
414 gboolean gee_abstract_collection_add (GeeAbstractCollection* self, gconstpointer item);
415 static void gee_hazard_pointer_free_node_instance_init (GeeHazardPointerFreeNode * self);
416 static void gee_hazard_pointer_node_instance_init (GeeHazardPointerNode * self);
417 gboolean gee_hazard_pointer_node_is_active (GeeHazardPointerNode* self);
418
419
420 /**
421  * Checks if the policy is concrete or if it depends on global variables.
422  *
423  * @return ``true`` if this policy does not depend on global variables
424  */
425 gboolean gee_hazard_pointer_policy_is_concrete (GeeHazardPointerPolicy self) {
426         gboolean result = FALSE;
427         switch (self) {
428                 case GEE_HAZARD_POINTER_POLICY_DEFAULT:
429                 case GEE_HAZARD_POINTER_POLICY_THREAD_EXIT:
430                 {
431                         result = FALSE;
432                         return result;
433                 }
434                 case GEE_HAZARD_POINTER_POLICY_TRY_FREE:
435                 case GEE_HAZARD_POINTER_POLICY_FREE:
436                 case GEE_HAZARD_POINTER_POLICY_TRY_RELEASE:
437                 case GEE_HAZARD_POINTER_POLICY_RELEASE:
438                 {
439                         result = TRUE;
440                         return result;
441                 }
442                 default:
443                 {
444                         g_assert_not_reached ();
445                 }
446         }
447 }
448
449
450 /**
451  * Checks if policy blocks or is lock-free.
452  * Please note that it works on a concrete policy only.
453  *
454  * @return ``true`` if the policy may block the thread.
455  */
456 gboolean gee_hazard_pointer_policy_is_blocking (GeeHazardPointerPolicy self) {
457         gboolean result = FALSE;
458         gboolean _tmp0_ = FALSE;
459         _tmp0_ = gee_hazard_pointer_policy_is_concrete (self);
460         g_return_val_if_fail (_tmp0_, FALSE);
461         switch (self) {
462                 case GEE_HAZARD_POINTER_POLICY_TRY_FREE:
463                 case GEE_HAZARD_POINTER_POLICY_TRY_RELEASE:
464                 {
465                         result = FALSE;
466                         return result;
467                 }
468                 case GEE_HAZARD_POINTER_POLICY_FREE:
469                 case GEE_HAZARD_POINTER_POLICY_RELEASE:
470                 {
471                         result = TRUE;
472                         return result;
473                 }
474                 default:
475                 {
476                         g_assert_not_reached ();
477                 }
478         }
479 }
480
481
482 /**
483  * Checks if policy guarantees freeing all elements.
484  * Please note that it works on a concrete policy only.
485  *
486  * @return ``true`` if the policy guarantees freeing all elements.
487  */
488 gboolean gee_hazard_pointer_policy_is_safe (GeeHazardPointerPolicy self) {
489         gboolean result = FALSE;
490         gboolean _tmp0_ = FALSE;
491         _tmp0_ = gee_hazard_pointer_policy_is_concrete (self);
492         g_return_val_if_fail (_tmp0_, FALSE);
493         switch (self) {
494                 case GEE_HAZARD_POINTER_POLICY_TRY_FREE:
495                 case GEE_HAZARD_POINTER_POLICY_TRY_RELEASE:
496                 {
497                         result = FALSE;
498                         return result;
499                 }
500                 case GEE_HAZARD_POINTER_POLICY_FREE:
501                 case GEE_HAZARD_POINTER_POLICY_RELEASE:
502                 {
503                         result = TRUE;
504                         return result;
505                 }
506                 default:
507                 {
508                         g_assert_not_reached ();
509                 }
510         }
511 }
512
513
514 /**
515  * Finds concrete policy which corresponds to given policy.
516  *
517  * @return Policy that corresponds to given policy at given time in given thread.
518  */
519 GeeHazardPointerPolicy gee_hazard_pointer_policy_to_concrete (GeeHazardPointerPolicy self) {
520         GeeHazardPointerPolicy result = 0;
521         switch (self) {
522                 case GEE_HAZARD_POINTER_POLICY_TRY_FREE:
523                 case GEE_HAZARD_POINTER_POLICY_FREE:
524                 case GEE_HAZARD_POINTER_POLICY_TRY_RELEASE:
525                 case GEE_HAZARD_POINTER_POLICY_RELEASE:
526                 {
527                         GeeHazardPointerPolicy _tmp0_;
528                         gboolean _tmp1_ = FALSE;
529                         result = self;
530                         _tmp0_ = result;
531                         _tmp1_ = gee_hazard_pointer_policy_is_concrete (_tmp0_);
532                         g_warn_if_fail (_tmp1_);
533                         return result;
534                 }
535                 case GEE_HAZARD_POINTER_POLICY_DEFAULT:
536                 {
537                         gint _tmp2_ = 0;
538                         GeeHazardPointerPolicy _tmp3_;
539                         gboolean _tmp4_ = FALSE;
540                         _tmp2_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer__default_policy));
541                         result = (GeeHazardPointerPolicy) _tmp2_;
542                         _tmp3_ = result;
543                         _tmp4_ = gee_hazard_pointer_policy_is_concrete (_tmp3_);
544                         g_warn_if_fail (_tmp4_);
545                         return result;
546                 }
547                 case GEE_HAZARD_POINTER_POLICY_THREAD_EXIT:
548                 {
549                         gint _tmp5_ = 0;
550                         GeeHazardPointerPolicy _tmp6_;
551                         gboolean _tmp7_ = FALSE;
552                         _tmp5_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer__thread_exit_policy));
553                         result = (GeeHazardPointerPolicy) _tmp5_;
554                         _tmp6_ = result;
555                         _tmp7_ = gee_hazard_pointer_policy_is_concrete (_tmp6_);
556                         g_warn_if_fail (_tmp7_);
557                         return result;
558                 }
559                 default:
560                 {
561                         g_assert_not_reached ();
562                 }
563         }
564 }
565
566
567 /**
568  * Runs the policy.
569  * @param to_free List containing elements to free.
570  * @return Non-empty list of not freed elements or ``null`` if all elements have been disposed.
571  */
572 GeeArrayList* gee_hazard_pointer_policy_perform (GeeHazardPointerPolicy self, GeeArrayList* to_free) {
573         GeeArrayList* result = NULL;
574         GeeHazardPointerPolicy _tmp0_ = 0;
575         g_return_val_if_fail (to_free != NULL, NULL);
576         _tmp0_ = gee_hazard_pointer_policy_to_concrete (self);
577         switch (_tmp0_) {
578                 case GEE_HAZARD_POINTER_POLICY_TRY_FREE:
579                 {
580                         GeeArrayList* _tmp1_ = NULL;
581                         GeeArrayList* _tmp2_;
582                         gboolean _tmp3_ = FALSE;
583                         _tmp2_ = to_free;
584                         _tmp3_ = gee_hazard_pointer_try_free (_tmp2_);
585                         if (_tmp3_) {
586                                 GeeArrayList* _tmp4_;
587                                 _tmp4_ = to_free;
588                                 to_free = NULL;
589                                 _g_object_unref0 (_tmp1_);
590                                 _tmp1_ = _tmp4_;
591                         } else {
592                                 _g_object_unref0 (_tmp1_);
593                                 _tmp1_ = NULL;
594                         }
595                         result = _tmp1_;
596                         _g_object_unref0 (to_free);
597                         return result;
598                 }
599                 case GEE_HAZARD_POINTER_POLICY_FREE:
600                 {
601                         while (TRUE) {
602                                 GeeArrayList* _tmp5_;
603                                 gboolean _tmp6_ = FALSE;
604                                 _tmp5_ = to_free;
605                                 _tmp6_ = gee_hazard_pointer_try_free (_tmp5_);
606                                 if (!_tmp6_) {
607                                         break;
608                                 }
609                                 g_thread_yield ();
610                         }
611                         result = NULL;
612                         _g_object_unref0 (to_free);
613                         return result;
614                 }
615                 case GEE_HAZARD_POINTER_POLICY_TRY_RELEASE:
616                 {
617                         gboolean _tmp7_ = FALSE;
618                         gee_hazard_pointer_release_policy_ensure_start ();
619                         _tmp7_ = g_static_mutex_trylock (&gee_hazard_pointer__queue_mutex);
620                         if (_tmp7_) {
621                                 GeeQueue* _tmp8_;
622                                 GeeArrayList* _tmp9_;
623                                 GeeArrayList* _tmp10_;
624                                 _tmp8_ = gee_hazard_pointer__queue;
625                                 _tmp9_ = to_free;
626                                 to_free = NULL;
627                                 _tmp10_ = _tmp9_;
628                                 gee_queue_offer (_tmp8_, _tmp10_);
629                                 _g_object_unref0 (_tmp10_);
630                                 g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
631                                 result = NULL;
632                                 _g_object_unref0 (to_free);
633                                 return result;
634                         } else {
635                                 GeeArrayList* _tmp11_;
636                                 _tmp11_ = to_free;
637                                 to_free = NULL;
638                                 result = _tmp11_;
639                                 _g_object_unref0 (to_free);
640                                 return result;
641                         }
642                 }
643                 case GEE_HAZARD_POINTER_POLICY_RELEASE:
644                 {
645                         GeeQueue* _tmp12_;
646                         GeeArrayList* _tmp13_;
647                         GeeArrayList* _tmp14_;
648                         gee_hazard_pointer_release_policy_ensure_start ();
649                         g_static_mutex_lock (&gee_hazard_pointer__queue_mutex);
650                         _tmp12_ = gee_hazard_pointer__queue;
651                         _tmp13_ = to_free;
652                         to_free = NULL;
653                         _tmp14_ = _tmp13_;
654                         gee_queue_offer (_tmp12_, _tmp14_);
655                         _g_object_unref0 (_tmp14_);
656                         g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
657                         result = NULL;
658                         _g_object_unref0 (to_free);
659                         return result;
660                 }
661                 default:
662                 {
663                         g_assert_not_reached ();
664                 }
665         }
666         _g_object_unref0 (to_free);
667 }
668
669
670 /**
671  * Policy determines what happens on exit from Context.
672  */
673 GType gee_hazard_pointer_policy_get_type (void) {
674         static volatile gsize gee_hazard_pointer_policy_type_id__volatile = 0;
675         if (g_once_init_enter (&gee_hazard_pointer_policy_type_id__volatile)) {
676                 static const GEnumValue values[] = {{GEE_HAZARD_POINTER_POLICY_DEFAULT, "GEE_HAZARD_POINTER_POLICY_DEFAULT", "default"}, {GEE_HAZARD_POINTER_POLICY_THREAD_EXIT, "GEE_HAZARD_POINTER_POLICY_THREAD_EXIT", "thread-exit"}, {GEE_HAZARD_POINTER_POLICY_TRY_FREE, "GEE_HAZARD_POINTER_POLICY_TRY_FREE", "try-free"}, {GEE_HAZARD_POINTER_POLICY_FREE, "GEE_HAZARD_POINTER_POLICY_FREE", "free"}, {GEE_HAZARD_POINTER_POLICY_TRY_RELEASE, "GEE_HAZARD_POINTER_POLICY_TRY_RELEASE", "try-release"}, {GEE_HAZARD_POINTER_POLICY_RELEASE, "GEE_HAZARD_POINTER_POLICY_RELEASE", "release"}, {0, NULL, NULL}};
677                 GType gee_hazard_pointer_policy_type_id;
678                 gee_hazard_pointer_policy_type_id = g_enum_register_static ("GeeHazardPointerPolicy", values);
679                 g_once_init_leave (&gee_hazard_pointer_policy_type_id__volatile, gee_hazard_pointer_policy_type_id);
680         }
681         return gee_hazard_pointer_policy_type_id__volatile;
682 }
683
684
685 static gboolean ___lambda33_ (void) {
686         gboolean result = FALSE;
687         GThread* _tmp0_ = NULL;
688         _tmp0_ = g_thread_self ();
689         g_thread_set_priority (_tmp0_, G_THREAD_PRIORITY_LOW);
690         while (TRUE) {
691                 g_thread_yield ();
692                 gee_hazard_pointer_release_policy_attempt_free ();
693         }
694         return result;
695 }
696
697
698 static gpointer ____lambda33__gthread_func (gpointer self) {
699         gpointer result;
700         result = ___lambda33_ ();
701         return result;
702 }
703
704
705 static gboolean ___lambda35_ (void) {
706         gboolean result = FALSE;
707         gee_hazard_pointer_release_policy_attempt_free ();
708         result = TRUE;
709         return result;
710 }
711
712
713 static gboolean ____lambda35__gsource_func (gpointer self) {
714         gboolean result;
715         result = ___lambda35_ ();
716         return result;
717 }
718
719
720 static void gee_hazard_pointer_release_policy_start (GeeHazardPointerReleasePolicy _self_) {
721         GeeHazardPointerReleasePolicy _tmp0_;
722         GError * _inner_error_ = NULL;
723         _tmp0_ = _self_;
724         switch (_tmp0_) {
725                 case GEE_HAZARD_POINTER_RELEASE_POLICY_HELPER_THREAD:
726                 {
727                         g_thread_create (____lambda33__gthread_func, NULL, FALSE, &_inner_error_);
728                         if (_inner_error_ != NULL) {
729                                 g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
730                                 g_clear_error (&_inner_error_);
731                                 return;
732                         }
733                         break;
734                 }
735                 case GEE_HAZARD_POINTER_RELEASE_POLICY_MAIN_LOOP:
736                 {
737                         g_idle_add_full (G_PRIORITY_LOW, ____lambda35__gsource_func, NULL, NULL);
738                         break;
739                 }
740                 default:
741                 {
742                         g_assert_not_reached ();
743                 }
744         }
745 }
746
747
748 /**
749  * Ensures that helper methods are started.
750  */
751 inline void gee_hazard_pointer_release_policy_ensure_start (void) {
752         gint _tmp0_ = 0;
753         gint policy;
754         gint _tmp1_;
755         gboolean _tmp2_ = FALSE;
756         _tmp0_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer_release_policy));
757         policy = _tmp0_;
758         _tmp1_ = policy;
759         if ((_tmp1_ & (1 << ((sizeof (gint) * 8) - 1))) != 0) {
760                 return;
761         }
762         _tmp2_ = g_static_mutex_trylock (&gee_hazard_pointer__queue_mutex);
763         if (_tmp2_) {
764                 gint _tmp3_ = 0;
765                 gint _tmp4_;
766                 _tmp3_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer_release_policy));
767                 policy = _tmp3_;
768                 _tmp4_ = policy;
769                 if ((_tmp4_ & (1 << ((sizeof (gint) * 8) - 1))) == 0) {
770                         GeeLinkedList* _tmp5_;
771                         gint _tmp6_ = 0;
772                         gint _tmp7_;
773                         _tmp5_ = gee_linked_list_new (GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL);
774                         _g_object_unref0 (gee_hazard_pointer__queue);
775                         gee_hazard_pointer__queue = (GeeQueue*) _tmp5_;
776                         _tmp6_ = g_atomic_int_exchange_and_add ((volatile gint *) (&gee_hazard_pointer_release_policy), (gint) (1 << ((sizeof (gint) * 8) - 1)));
777                         policy = _tmp6_;
778                         _tmp7_ = policy;
779                         gee_hazard_pointer_release_policy_start ((GeeHazardPointerReleasePolicy) _tmp7_);
780                 }
781                 g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
782         }
783 }
784
785
786 static gboolean ___lambda34_ (GeeArrayList* x) {
787         gboolean result = FALSE;
788         GeeArrayList* _tmp0_;
789         GeeArrayList* _tmp1_;
790         g_return_val_if_fail (x != NULL, FALSE);
791         _tmp0_ = gee_hazard_pointer__global_to_free;
792         _tmp1_ = x;
793         gee_array_list_add_all (_tmp0_, (GeeCollection*) _tmp1_);
794         result = TRUE;
795         _g_object_unref0 (x);
796         return result;
797 }
798
799
800 static gboolean ____lambda34__gee_forall_func (gpointer g, gpointer self) {
801         gboolean result;
802         result = ___lambda34_ (g);
803         return result;
804 }
805
806
807 static inline void gee_hazard_pointer_release_policy_attempt_free (void) {
808         gboolean _tmp0_ = FALSE;
809         GeeArrayList* _tmp5_;
810         _tmp0_ = g_static_mutex_trylock (&gee_hazard_pointer__queue_mutex);
811         if (_tmp0_) {
812                 GeeArrayList* _tmp1_;
813                 GeeCollection* temp;
814                 GeeQueue* _tmp2_;
815                 GeeCollection* _tmp3_;
816                 GeeCollection* _tmp4_;
817                 _tmp1_ = gee_array_list_new (GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL);
818                 temp = (GeeCollection*) _tmp1_;
819                 _tmp2_ = gee_hazard_pointer__queue;
820                 _tmp3_ = temp;
821                 gee_queue_drain (_tmp2_, _tmp3_, -1);
822                 g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
823                 _tmp4_ = temp;
824                 gee_traversable_foreach ((GeeTraversable*) _tmp4_, ____lambda34__gee_forall_func, NULL);
825                 _g_object_unref0 (temp);
826         }
827         _tmp5_ = gee_hazard_pointer__global_to_free;
828         gee_hazard_pointer_try_free (_tmp5_);
829 }
830
831
832 /**
833  * Release policy determines what happens with object freed by Policy.TRY_RELEASE
834  * and Policy.RELEASE.
835  */
836 GType gee_hazard_pointer_release_policy_get_type (void) {
837         static volatile gsize gee_hazard_pointer_release_policy_type_id__volatile = 0;
838         if (g_once_init_enter (&gee_hazard_pointer_release_policy_type_id__volatile)) {
839                 static const GEnumValue values[] = {{GEE_HAZARD_POINTER_RELEASE_POLICY_HELPER_THREAD, "GEE_HAZARD_POINTER_RELEASE_POLICY_HELPER_THREAD", "helper-thread"}, {GEE_HAZARD_POINTER_RELEASE_POLICY_MAIN_LOOP, "GEE_HAZARD_POINTER_RELEASE_POLICY_MAIN_LOOP", "main-loop"}, {0, NULL, NULL}};
840                 GType gee_hazard_pointer_release_policy_type_id;
841                 gee_hazard_pointer_release_policy_type_id = g_enum_register_static ("GeeHazardPointerReleasePolicy", values);
842                 g_once_init_leave (&gee_hazard_pointer_release_policy_type_id__volatile, gee_hazard_pointer_release_policy_type_id);
843         }
844         return gee_hazard_pointer_release_policy_type_id__volatile;
845 }
846
847
848 /**
849  * Creates a hazard pointer for a pointer.
850  *
851  * @param ptr Protected pointer
852  */
853 GeeHazardPointer* gee_hazard_pointer_new (gconstpointer* ptr) {
854         GeeHazardPointer* self;
855         GeeHazardPointerNode* _tmp0_ = NULL;
856         GeeHazardPointerNode* _tmp1_;
857         gconstpointer* _tmp2_;
858         self = g_slice_new0 (GeeHazardPointer);
859         gee_hazard_pointer_instance_init (self);
860         _tmp0_ = gee_hazard_pointer_acquire ();
861         self->_node = _tmp0_;
862         _tmp1_ = self->_node;
863         _tmp2_ = ptr;
864         gee_hazard_pointer_node_set (_tmp1_, (void*) _tmp2_);
865         return self;
866 }
867
868
869 /**
870  * Create a hazard pointer from Node.
871  */
872 GeeHazardPointer* gee_hazard_pointer_new_from_node (GeeHazardPointerNode* node) {
873         GeeHazardPointer* self;
874         GeeHazardPointerNode* _tmp0_;
875         g_return_val_if_fail (node != NULL, NULL);
876         self = g_slice_new0 (GeeHazardPointer);
877         gee_hazard_pointer_instance_init (self);
878         _tmp0_ = node;
879         self->_node = _tmp0_;
880         return self;
881 }
882
883
884 /**
885  * Gets hazard pointer from atomic pointer safely.
886  *
887  * @param aptr Atomic pointer.
888  * @param mask Mask of bits.
889  * @param mask_out Result of mask.
890  * @return Hazard pointer containing the element.
891  */
892 GeeHazardPointer* gee_hazard_pointer_get_hazard_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gsize mask, gsize* mask_out) {
893         gsize _vala_mask_out = 0UL;
894         GeeHazardPointer* result = NULL;
895         GeeHazardPointerNode* _tmp0_ = NULL;
896         GeeHazardPointerNode* node;
897         void* rptr;
898         void* ptr;
899         void* _tmp14_;
900         _tmp0_ = gee_hazard_pointer_acquire ();
901         node = _tmp0_;
902         rptr = NULL;
903         ptr = NULL;
904         _vala_mask_out = (gsize) 0;
905         {
906                 gboolean _tmp1_;
907                 _tmp1_ = TRUE;
908                 while (TRUE) {
909                         gboolean _tmp2_;
910                         gconstpointer** _tmp6_;
911                         void* _tmp7_ = NULL;
912                         void* _tmp8_;
913                         gsize _tmp9_;
914                         void* _tmp10_;
915                         gsize _tmp11_;
916                         GeeHazardPointerNode* _tmp12_;
917                         void* _tmp13_;
918                         _tmp2_ = _tmp1_;
919                         if (!_tmp2_) {
920                                 void* _tmp3_;
921                                 gconstpointer** _tmp4_;
922                                 void* _tmp5_ = NULL;
923                                 _tmp3_ = rptr;
924                                 _tmp4_ = aptr;
925                                 _tmp5_ = g_atomic_pointer_get ((volatile gpointer *) ((void**) _tmp4_));
926                                 if (!(_tmp3_ != _tmp5_)) {
927                                         break;
928                                 }
929                         }
930                         _tmp1_ = FALSE;
931                         _tmp6_ = aptr;
932                         _tmp7_ = g_atomic_pointer_get ((volatile gpointer *) ((void**) _tmp6_));
933                         rptr = _tmp7_;
934                         _tmp8_ = rptr;
935                         _tmp9_ = mask;
936                         ptr = (void*) (((gsize) _tmp8_) & (~_tmp9_));
937                         _tmp10_ = rptr;
938                         _tmp11_ = mask;
939                         _vala_mask_out = ((gsize) _tmp10_) & _tmp11_;
940                         _tmp12_ = node;
941                         _tmp13_ = ptr;
942                         gee_hazard_pointer_node_set (_tmp12_, _tmp13_);
943                 }
944         }
945         _tmp14_ = ptr;
946         if (_tmp14_ != NULL) {
947                 GeeHazardPointerNode* _tmp15_;
948                 GeeHazardPointer* _tmp16_;
949                 _tmp15_ = node;
950                 _tmp16_ = gee_hazard_pointer_new_from_node (_tmp15_);
951                 result = _tmp16_;
952                 if (mask_out) {
953                         *mask_out = _vala_mask_out;
954                 }
955                 return result;
956         } else {
957                 GeeHazardPointerNode* _tmp17_;
958                 _tmp17_ = node;
959                 gee_hazard_pointer_node_release (_tmp17_);
960                 result = NULL;
961                 if (mask_out) {
962                         *mask_out = _vala_mask_out;
963                 }
964                 return result;
965         }
966         if (mask_out) {
967                 *mask_out = _vala_mask_out;
968         }
969 }
970
971
972 /**
973  * Copy an object from atomic pointer.
974  *
975  * @param aptr Atomic pointer.
976  * @param mask Mask of flags.
977  * @param mask_out Result of mask.
978  * @return A copy of object from atomic pointer.
979  */
980 gpointer gee_hazard_pointer_get_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gsize mask, gsize* mask_out) {
981         gsize _vala_mask_out = 0UL;
982         gpointer result = NULL;
983         GeeHazardPointerNode* _tmp0_ = NULL;
984         GeeHazardPointerNode* node;
985         void* rptr;
986         void* ptr;
987         void* _tmp14_;
988         gpointer _tmp15_;
989         gpointer res;
990         GeeHazardPointerNode* _tmp16_;
991         _tmp0_ = gee_hazard_pointer_acquire ();
992         node = _tmp0_;
993         rptr = NULL;
994         ptr = NULL;
995         _vala_mask_out = (gsize) 0;
996         {
997                 gboolean _tmp1_;
998                 _tmp1_ = TRUE;
999                 while (TRUE) {
1000                         gboolean _tmp2_;
1001                         gconstpointer** _tmp6_;
1002                         void* _tmp7_ = NULL;
1003                         void* _tmp8_;
1004                         gsize _tmp9_;
1005                         void* _tmp10_;
1006                         gsize _tmp11_;
1007                         GeeHazardPointerNode* _tmp12_;
1008                         void* _tmp13_;
1009                         _tmp2_ = _tmp1_;
1010                         if (!_tmp2_) {
1011                                 void* _tmp3_;
1012                                 gconstpointer** _tmp4_;
1013                                 void* _tmp5_ = NULL;
1014                                 _tmp3_ = rptr;
1015                                 _tmp4_ = aptr;
1016                                 _tmp5_ = g_atomic_pointer_get ((volatile gpointer *) ((void**) _tmp4_));
1017                                 if (!(_tmp3_ != _tmp5_)) {
1018                                         break;
1019                                 }
1020                         }
1021                         _tmp1_ = FALSE;
1022                         _tmp6_ = aptr;
1023                         _tmp7_ = g_atomic_pointer_get ((volatile gpointer *) ((void**) _tmp6_));
1024                         rptr = _tmp7_;
1025                         _tmp8_ = rptr;
1026                         _tmp9_ = mask;
1027                         ptr = (void*) (((gsize) _tmp8_) & (~_tmp9_));
1028                         _tmp10_ = rptr;
1029                         _tmp11_ = mask;
1030                         _vala_mask_out = ((gsize) _tmp10_) & _tmp11_;
1031                         _tmp12_ = node;
1032                         _tmp13_ = ptr;
1033                         gee_hazard_pointer_node_set (_tmp12_, _tmp13_);
1034                 }
1035         }
1036         _tmp14_ = ptr;
1037         _tmp15_ = ((((gconstpointer*) _tmp14_) != NULL) && (g_dup_func != NULL)) ? g_dup_func ((gpointer) ((gconstpointer*) _tmp14_)) : ((gpointer) ((gconstpointer*) _tmp14_));
1038         res = _tmp15_;
1039         _tmp16_ = node;
1040         gee_hazard_pointer_node_release (_tmp16_);
1041         result = res;
1042         if (mask_out) {
1043                 *mask_out = _vala_mask_out;
1044         }
1045         return result;
1046 }
1047
1048
1049 /**
1050  * Exchange objects safly.
1051  *
1052  * @param aptr Atomic pointer.
1053  * @param new_ptr New value
1054  * @param mask Mask of flags.
1055  * @param new_mask New mask.
1056  * @param old_mask Previous mask mask.
1057  * @return Hazard pointer containing old value.
1058  */
1059 GeeHazardPointer* gee_hazard_pointer_exchange_hazard_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gpointer new_ptr, gsize mask, gsize new_mask, gsize* old_mask) {
1060         gsize _vala_old_mask = 0UL;
1061         GeeHazardPointer* result = NULL;
1062         GeeHazardPointerNode* new_node;
1063         gconstpointer _tmp0_;
1064         gpointer _tmp4_;
1065         gsize _tmp5_;
1066         gsize _tmp6_;
1067         void* new_rptr;
1068         GeeHazardPointerNode* _tmp7_ = NULL;
1069         GeeHazardPointerNode* node;
1070         void* rptr;
1071         void* ptr;
1072         GeeHazardPointerNode* _tmp22_;
1073         void* _tmp24_;
1074         new_node = NULL;
1075         _tmp0_ = new_ptr;
1076         if (_tmp0_ != NULL) {
1077                 GeeHazardPointerNode* _tmp1_ = NULL;
1078                 GeeHazardPointerNode* _tmp2_;
1079                 gconstpointer _tmp3_;
1080                 _tmp1_ = gee_hazard_pointer_acquire ();
1081                 new_node = _tmp1_;
1082                 _tmp2_ = new_node;
1083                 _tmp3_ = new_ptr;
1084                 gee_hazard_pointer_node_set (_tmp2_, _tmp3_);
1085         }
1086         _vala_old_mask = (gsize) 0;
1087         _tmp4_ = new_ptr;
1088         new_ptr = NULL;
1089         _tmp5_ = mask;
1090         _tmp6_ = new_mask;
1091         new_rptr = (void*) (((gsize) _tmp4_) | (_tmp5_ & _tmp6_));
1092         _tmp7_ = gee_hazard_pointer_acquire ();
1093         node = _tmp7_;
1094         rptr = NULL;
1095         ptr = NULL;
1096         {
1097                 gboolean _tmp8_;
1098                 _tmp8_ = TRUE;
1099                 while (TRUE) {
1100                         gboolean _tmp9_;
1101                         gconstpointer** _tmp14_;
1102                         void* _tmp15_ = NULL;
1103                         void* _tmp16_;
1104                         gsize _tmp17_;
1105                         void* _tmp18_;
1106                         gsize _tmp19_;
1107                         GeeHazardPointerNode* _tmp20_;
1108                         void* _tmp21_;
1109                         _tmp9_ = _tmp8_;
1110                         if (!_tmp9_) {
1111                                 gconstpointer** _tmp10_;
1112                                 void* _tmp11_;
1113                                 void* _tmp12_;
1114                                 gboolean _tmp13_ = FALSE;
1115                                 _tmp10_ = aptr;
1116                                 _tmp11_ = rptr;
1117                                 _tmp12_ = new_rptr;
1118                                 _tmp13_ = g_atomic_pointer_compare_and_exchange ((volatile gpointer *) ((void**) _tmp10_), _tmp11_, _tmp12_);
1119                                 if (!(!_tmp13_)) {
1120                                         break;
1121                                 }
1122                         }
1123                         _tmp8_ = FALSE;
1124                         _tmp14_ = aptr;
1125                         _tmp15_ = g_atomic_pointer_get ((volatile gpointer *) ((void**) _tmp14_));
1126                         rptr = _tmp15_;
1127                         _tmp16_ = rptr;
1128                         _tmp17_ = mask;
1129                         ptr = (void*) (((gsize) _tmp16_) & (~_tmp17_));
1130                         _tmp18_ = rptr;
1131                         _tmp19_ = mask;
1132                         _vala_old_mask = ((gsize) _tmp18_) & _tmp19_;
1133                         _tmp20_ = node;
1134                         _tmp21_ = ptr;
1135                         gee_hazard_pointer_node_set (_tmp20_, _tmp21_);
1136                 }
1137         }
1138         _tmp22_ = new_node;
1139         if (_tmp22_ != NULL) {
1140                 GeeHazardPointerNode* _tmp23_;
1141                 _tmp23_ = new_node;
1142                 gee_hazard_pointer_node_release (_tmp23_);
1143         }
1144         _tmp24_ = ptr;
1145         if (_tmp24_ != NULL) {
1146                 GeeHazardPointerNode* _tmp25_;
1147                 GeeHazardPointer* _tmp26_;
1148                 _tmp25_ = node;
1149                 _tmp26_ = gee_hazard_pointer_new_from_node (_tmp25_);
1150                 result = _tmp26_;
1151                 _g_destroy_func0 (new_ptr);
1152                 if (old_mask) {
1153                         *old_mask = _vala_old_mask;
1154                 }
1155                 return result;
1156         } else {
1157                 GeeHazardPointerNode* _tmp27_;
1158                 _tmp27_ = node;
1159                 gee_hazard_pointer_node_release (_tmp27_);
1160                 result = NULL;
1161                 _g_destroy_func0 (new_ptr);
1162                 if (old_mask) {
1163                         *old_mask = _vala_old_mask;
1164                 }
1165                 return result;
1166         }
1167         _g_destroy_func0 (new_ptr);
1168         if (old_mask) {
1169                 *old_mask = _vala_old_mask;
1170         }
1171 }
1172
1173
1174 /**
1175  * Sets object safely
1176  *
1177  * @param aptr Atomic pointer.
1178  * @param new_ptr New value
1179  * @param mask Mask of flags.
1180  * @param new_mask New mask.
1181  */
1182 void gee_hazard_pointer_set_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gpointer new_ptr, gsize mask, gsize new_mask) {
1183         gconstpointer** _tmp0_;
1184         gconstpointer _tmp1_;
1185         gpointer _tmp2_;
1186         gsize _tmp3_;
1187         gsize _tmp4_;
1188         GeeHazardPointer* _tmp5_ = NULL;
1189         GeeHazardPointer* ptr;
1190         GeeHazardPointer* _tmp6_;
1191         _tmp0_ = aptr;
1192         _tmp1_ = new_ptr;
1193         _tmp2_ = ((_tmp1_ != NULL) && (g_dup_func != NULL)) ? g_dup_func ((gpointer) _tmp1_) : ((gpointer) _tmp1_);
1194         _tmp3_ = mask;
1195         _tmp4_ = new_mask;
1196         _tmp5_ = gee_hazard_pointer_exchange_hazard_pointer (g_type, (GBoxedCopyFunc) g_dup_func, g_destroy_func, _tmp0_, _tmp2_, _tmp3_, _tmp4_, NULL);
1197         ptr = _tmp5_;
1198         _tmp6_ = ptr;
1199         if (_tmp6_ != NULL) {
1200                 void* _tmp7_ = NULL;
1201                 GDestroyNotify _tmp8_ = NULL;
1202                 GeeHazardPointerDestroyNotify _tmp9_ = NULL;
1203                 GeeHazardPointerDestroyNotify notify;
1204                 void* notify_target;
1205                 GDestroyNotify notify_target_destroy_notify;
1206                 GeeHazardPointer* _tmp10_;
1207                 GeeHazardPointerDestroyNotify _tmp11_;
1208                 void* _tmp11__target;
1209                 GDestroyNotify _tmp11__target_destroy_notify;
1210                 _tmp9_ = gee_hazard_pointer_get_destroy_notify (g_type, (GBoxedCopyFunc) g_dup_func, g_destroy_func, &_tmp7_, &_tmp8_);
1211                 notify = _tmp9_;
1212                 notify_target = _tmp7_;
1213                 notify_target_destroy_notify = _tmp8_;
1214                 _tmp10_ = ptr;
1215                 _tmp11_ = notify;
1216                 _tmp11__target = notify_target;
1217                 _tmp11__target_destroy_notify = notify_target_destroy_notify;
1218                 notify_target_destroy_notify = NULL;
1219                 gee_hazard_pointer_release (_tmp10_, _tmp11_, _tmp11__target, _tmp11__target_destroy_notify);
1220                 (notify_target_destroy_notify == NULL) ? NULL : (notify_target_destroy_notify (notify_target), NULL);
1221                 notify = NULL;
1222                 notify_target = NULL;
1223                 notify_target_destroy_notify = NULL;
1224         }
1225         _gee_hazard_pointer_free0 (ptr);
1226         _g_destroy_func0 (new_ptr);
1227 }
1228
1229
1230 /**
1231  * Exchange objects safly.
1232  *
1233  * @param aptr Atomic pointer.
1234  * @param new_ptr New value
1235  * @param mask Mask of flags.
1236  * @param new_mask New mask.
1237  * @param old_mask Previous mask mask.
1238  * @return Value that was previously stored.
1239  */
1240 gpointer gee_hazard_pointer_exchange_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gpointer new_ptr, gsize mask, gsize new_mask, gsize* old_mask) {
1241         gsize _vala_old_mask = 0UL;
1242         gpointer result = NULL;
1243         gconstpointer** _tmp0_;
1244         gconstpointer _tmp1_;
1245         gpointer _tmp2_;
1246         gsize _tmp3_;
1247         gsize _tmp4_;
1248         gsize _tmp5_ = 0UL;
1249         GeeHazardPointer* _tmp6_ = NULL;
1250         GeeHazardPointer* ptr;
1251         gconstpointer _tmp7_ = NULL;
1252         GeeHazardPointer* _tmp8_;
1253         gconstpointer _tmp11_;
1254         gpointer _tmp12_;
1255         gpointer rptr;
1256         _tmp0_ = aptr;
1257         _tmp1_ = new_ptr;
1258         _tmp2_ = ((_tmp1_ != NULL) && (g_dup_func != NULL)) ? g_dup_func ((gpointer) _tmp1_) : ((gpointer) _tmp1_);
1259         _tmp3_ = mask;
1260         _tmp4_ = new_mask;
1261         _tmp6_ = gee_hazard_pointer_exchange_hazard_pointer (g_type, (GBoxedCopyFunc) g_dup_func, g_destroy_func, _tmp0_, _tmp2_, _tmp3_, _tmp4_, &_tmp5_);
1262         _vala_old_mask = _tmp5_;
1263         ptr = _tmp6_;
1264         _tmp8_ = ptr;
1265         if (_tmp8_ != NULL) {
1266                 GeeHazardPointer* _tmp9_;
1267                 gconstpointer _tmp10_ = NULL;
1268                 _tmp9_ = ptr;
1269                 _tmp10_ = gee_hazard_pointer_get (_tmp9_, FALSE);
1270                 _tmp7_ = _tmp10_;
1271         } else {
1272                 _tmp7_ = NULL;
1273         }
1274         _tmp11_ = _tmp7_;
1275         _tmp12_ = ((_tmp11_ != NULL) && (g_dup_func != NULL)) ? g_dup_func ((gpointer) _tmp11_) : ((gpointer) _tmp11_);
1276         rptr = _tmp12_;
1277         result = rptr;
1278         _gee_hazard_pointer_free0 (ptr);
1279         _g_destroy_func0 (new_ptr);
1280         if (old_mask) {
1281                 *old_mask = _vala_old_mask;
1282         }
1283         return result;
1284 }
1285
1286
1287 /**
1288  * Compares and exchanges objects.
1289  *
1290  * @param aptr Atomic pointer.
1291  * @param old_ptr Old pointer.
1292  * @param _new_ptr New value.
1293  * @param old_mask Old mask.
1294  * @param new_mask New mask.
1295  * @return Value that was previously stored.
1296  */
1297 gboolean gee_hazard_pointer_compare_and_exchange_pointer (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, gconstpointer** aptr, gconstpointer old_ptr, gpointer _new_ptr, gsize mask, gsize old_mask, gsize new_mask) {
1298         gboolean result = FALSE;
1299         gpointer _tmp0_;
1300         gconstpointer* new_ptr;
1301         gconstpointer* _tmp1_;
1302         gsize _tmp2_;
1303         gsize _tmp3_;
1304         void* new_rptr;
1305         gconstpointer _tmp4_;
1306         gsize _tmp5_;
1307         gsize _tmp6_;
1308         void* old_rptr;
1309         gconstpointer** _tmp7_;
1310         void* _tmp8_;
1311         void* _tmp9_;
1312         gboolean _tmp10_ = FALSE;
1313         gboolean success;
1314         gboolean _tmp11_;
1315         _tmp0_ = _new_ptr;
1316         _new_ptr = NULL;
1317         new_ptr = _tmp0_;
1318         _tmp1_ = new_ptr;
1319         _tmp2_ = mask;
1320         _tmp3_ = new_mask;
1321         new_rptr = (void*) (((gsize) _tmp1_) | (_tmp2_ & _tmp3_));
1322         _tmp4_ = old_ptr;
1323         _tmp5_ = mask;
1324         _tmp6_ = old_mask;
1325         old_rptr = (void*) (((gsize) _tmp4_) | (_tmp5_ & _tmp6_));
1326         _tmp7_ = aptr;
1327         _tmp8_ = old_rptr;
1328         _tmp9_ = new_rptr;
1329         _tmp10_ = g_atomic_pointer_compare_and_exchange ((volatile gpointer *) ((void**) _tmp7_), _tmp8_, _tmp9_);
1330         success = _tmp10_;
1331         _tmp11_ = success;
1332         if (_tmp11_) {
1333                 void* _tmp12_ = NULL;
1334                 GDestroyNotify _tmp13_ = NULL;
1335                 GeeHazardPointerDestroyNotify _tmp14_ = NULL;
1336                 GeeHazardPointerDestroyNotify notify;
1337                 void* notify_target;
1338                 GDestroyNotify notify_target_destroy_notify;
1339                 gconstpointer _tmp15_;
1340                 _tmp14_ = gee_hazard_pointer_get_destroy_notify (g_type, (GBoxedCopyFunc) g_dup_func, g_destroy_func, &_tmp12_, &_tmp13_);
1341                 notify = _tmp14_;
1342                 notify_target = _tmp12_;
1343                 notify_target_destroy_notify = _tmp13_;
1344                 _tmp15_ = old_ptr;
1345                 if (_tmp15_ != NULL) {
1346                         GeeHazardPointerContext* _tmp16_ = NULL;
1347                         gconstpointer _tmp17_;
1348                         GeeHazardPointerDestroyNotify _tmp18_;
1349                         void* _tmp18__target;
1350                         GDestroyNotify _tmp18__target_destroy_notify;
1351                         _tmp16_ = gee_hazard_pointer_context_get_current_context ();
1352                         _tmp17_ = old_ptr;
1353                         _tmp18_ = notify;
1354                         _tmp18__target = notify_target;
1355                         _tmp18__target_destroy_notify = notify_target_destroy_notify;
1356                         notify_target_destroy_notify = NULL;
1357                         gee_hazard_pointer_context_release_ptr (_tmp16_, _tmp17_, _tmp18_, _tmp18__target, _tmp18__target_destroy_notify);
1358                 }
1359                 (notify_target_destroy_notify == NULL) ? NULL : (notify_target_destroy_notify (notify_target), NULL);
1360                 notify = NULL;
1361                 notify_target = NULL;
1362                 notify_target_destroy_notify = NULL;
1363         } else {
1364                 gconstpointer* _tmp19_;
1365                 _tmp19_ = new_ptr;
1366                 if (_tmp19_ != NULL) {
1367                         gconstpointer* _tmp20_;
1368                         _tmp20_ = new_ptr;
1369                         new_ptr = NULL;
1370                         _g_destroy_func0 (_new_ptr);
1371                         _new_ptr = _tmp20_;
1372                 }
1373         }
1374         result = success;
1375         _g_destroy_func0 (_new_ptr);
1376         return result;
1377 }
1378
1379
1380 /**
1381  * Gets the pointer hold by hazard pointer.
1382  *
1383  * @param other_thread Have to be set to ``true`` if accessed from thread that did not create this thread.
1384  * @return The value hold by pointer.
1385  */
1386 inline gconstpointer gee_hazard_pointer_get (GeeHazardPointer* self, gboolean other_thread) {
1387         gconstpointer result = NULL;
1388         GeeHazardPointerNode* _tmp0_;
1389         gboolean _tmp1_;
1390         void* _tmp2_ = NULL;
1391         g_return_val_if_fail (self != NULL, NULL);
1392         _tmp0_ = self->_node;
1393         _tmp1_ = other_thread;
1394         _tmp2_ = gee_hazard_pointer_node_get (_tmp0_, _tmp1_);
1395         result = _tmp2_;
1396         return result;
1397 }
1398
1399
1400 /**
1401  * Free the pointer.
1402  *
1403  * @param notify method freeing object
1404  */
1405 void gee_hazard_pointer_release (GeeHazardPointer* self, GeeHazardPointerDestroyNotify notify, void* notify_target, GDestroyNotify notify_target_destroy_notify) {
1406         GeeHazardPointerNode* _tmp0_;
1407         void* _tmp1_ = NULL;
1408         gconstpointer item;
1409         GeeHazardPointerNode* _tmp2_;
1410         gconstpointer _tmp3_;
1411         g_return_if_fail (self != NULL);
1412         _tmp0_ = self->_node;
1413         _tmp1_ = gee_hazard_pointer_node_get (_tmp0_, FALSE);
1414         item = _tmp1_;
1415         _tmp2_ = self->_node;
1416         gee_hazard_pointer_node_set (_tmp2_, NULL);
1417         _tmp3_ = item;
1418         if (_tmp3_ != NULL) {
1419                 GeeHazardPointerContext* _tmp4_ = NULL;
1420                 gconstpointer _tmp5_;
1421                 GeeHazardPointerDestroyNotify _tmp6_;
1422                 void* _tmp6__target;
1423                 GDestroyNotify _tmp6__target_destroy_notify;
1424                 _tmp4_ = gee_hazard_pointer_context_get_current_context ();
1425                 _tmp5_ = item;
1426                 _tmp6_ = notify;
1427                 _tmp6__target = notify_target;
1428                 _tmp6__target_destroy_notify = notify_target_destroy_notify;
1429                 notify_target_destroy_notify = NULL;
1430                 gee_hazard_pointer_context_release_ptr (_tmp4_, _tmp5_, _tmp6_, _tmp6__target, _tmp6__target_destroy_notify);
1431         }
1432         (notify_target_destroy_notify == NULL) ? NULL : (notify_target_destroy_notify (notify_target), NULL);
1433         notify = NULL;
1434         notify_target = NULL;
1435         notify_target_destroy_notify = NULL;
1436 }
1437
1438
1439 /**
1440  * Sets default policy (i.e. default policy for user-created contexts).
1441  * The policy must be concrete and should not be blocking.
1442  *
1443  * @param policy New default policy.
1444  */
1445 void gee_hazard_pointer_set_default_policy (GeeHazardPointerPolicy policy) {
1446         GeeHazardPointerPolicy _tmp0_;
1447         gboolean _tmp1_ = FALSE;
1448         GeeHazardPointerPolicy _tmp2_;
1449         gboolean _tmp3_ = FALSE;
1450         GeeHazardPointerPolicy _tmp4_;
1451         _tmp0_ = policy;
1452         _tmp1_ = gee_hazard_pointer_policy_is_concrete (_tmp0_);
1453         g_return_if_fail (_tmp1_);
1454         _tmp2_ = policy;
1455         _tmp3_ = gee_hazard_pointer_policy_is_blocking (_tmp2_);
1456         if (_tmp3_) {
1457                 g_warning ("hazardpointer.vala:250: Setting blocking defautl Gee.HazardPointer.Pol" \
1458 "icy (there may be a deadlock).\n");
1459         }
1460         _tmp4_ = policy;
1461         g_atomic_int_set ((volatile gint *) (&gee_hazard_pointer__default_policy), (gint) _tmp4_);
1462 }
1463
1464
1465 /**
1466  * Sets thread exit policy (i.e. default policy for the top-most Context).
1467  * The policy must be concrete and should not be unsafe.
1468  *
1469  * @param policy New thread policy.
1470  */
1471 void gee_hazard_pointer_set_thread_exit_policy (GeeHazardPointerPolicy policy) {
1472         GeeHazardPointerPolicy _tmp0_;
1473         gboolean _tmp1_ = FALSE;
1474         GeeHazardPointerPolicy _tmp2_;
1475         gboolean _tmp3_ = FALSE;
1476         GeeHazardPointerPolicy _tmp4_;
1477         _tmp0_ = policy;
1478         _tmp1_ = gee_hazard_pointer_policy_is_concrete (_tmp0_);
1479         g_return_if_fail (_tmp1_);
1480         _tmp2_ = policy;
1481         _tmp3_ = gee_hazard_pointer_policy_is_safe (_tmp2_);
1482         if (!_tmp3_) {
1483                 g_warning ("hazardpointer.vala:262: Setting unsafe globale thread-exit Gee.HazardP" \
1484 "ointer.Policy (there may be a memory leak).\n");
1485         }
1486         _tmp4_ = policy;
1487         g_atomic_int_set ((volatile gint *) (&gee_hazard_pointer__thread_exit_policy), (gint) _tmp4_);
1488 }
1489
1490
1491 /**
1492  * Sets release (i.e. how exactly the released objects arefreed).
1493  *
1494  * The method can be only set before any objects is released and is not thread-safe.
1495  *
1496  * @param policy New release policy.
1497  */
1498 gboolean gee_hazard_pointer_set_release_policy (GeeHazardPointerReleasePolicy policy) {
1499         gboolean result = FALSE;
1500         gint _tmp0_ = 0;
1501         gint old_policy;
1502         gint _tmp1_;
1503         gint _tmp2_;
1504         GeeHazardPointerReleasePolicy _tmp3_;
1505         gboolean _tmp4_ = FALSE;
1506         _tmp0_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer_release_policy));
1507         old_policy = _tmp0_;
1508         _tmp1_ = old_policy;
1509         if ((_tmp1_ & ((sizeof (gint) * 8) - 1)) != 0) {
1510                 g_critical ("hazardpointer.vala:276: Attempt to change the policy of running helper" \
1511 ". Failing.");
1512                 result = FALSE;
1513                 return result;
1514         }
1515         _tmp2_ = old_policy;
1516         _tmp3_ = policy;
1517         _tmp4_ = g_atomic_int_compare_and_exchange ((volatile gint *) (&gee_hazard_pointer_release_policy), _tmp2_, (gint) _tmp3_);
1518         if (!_tmp4_) {
1519                 g_critical ("hazardpointer.vala:280: Concurrent access to release policy detected. " \
1520 "Failing.");
1521                 result = FALSE;
1522                 return result;
1523         }
1524         result = TRUE;
1525         return result;
1526 }
1527
1528
1529 /**
1530  * Gets a new hazard pointer node.
1531  *
1532  * @return new hazard pointer node.
1533  */
1534 inline GeeHazardPointerNode* gee_hazard_pointer_acquire (void) {
1535         GeeHazardPointerNode* result = NULL;
1536         GeeHazardPointerNode* _tmp9_;
1537         GeeHazardPointerNode* node;
1538         GeeHazardPointerNode* old_head;
1539         GeeHazardPointerNode* _tmp18_;
1540         {
1541                 GeeHazardPointerNode* _tmp0_ = NULL;
1542                 GeeHazardPointerNode* curr;
1543                 _tmp0_ = gee_hazard_pointer_get_head ();
1544                 curr = _tmp0_;
1545                 {
1546                         gboolean _tmp1_;
1547                         _tmp1_ = TRUE;
1548                         while (TRUE) {
1549                                 gboolean _tmp2_;
1550                                 GeeHazardPointerNode* _tmp5_;
1551                                 GeeHazardPointerNode* _tmp6_;
1552                                 gboolean _tmp7_ = FALSE;
1553                                 _tmp2_ = _tmp1_;
1554                                 if (!_tmp2_) {
1555                                         GeeHazardPointerNode* _tmp3_;
1556                                         GeeHazardPointerNode* _tmp4_ = NULL;
1557                                         _tmp3_ = curr;
1558                                         _tmp4_ = gee_hazard_pointer_node_get_next (_tmp3_);
1559                                         curr = _tmp4_;
1560                                 }
1561                                 _tmp1_ = FALSE;
1562                                 _tmp5_ = curr;
1563                                 if (!(_tmp5_ != NULL)) {
1564                                         break;
1565                                 }
1566                                 _tmp6_ = curr;
1567                                 _tmp7_ = gee_hazard_pointer_node_activate (_tmp6_);
1568                                 if (_tmp7_) {
1569                                         GeeHazardPointerNode* _tmp8_;
1570                                         _tmp8_ = curr;
1571                                         result = _tmp8_;
1572                                         return result;
1573                                 }
1574                         }
1575                 }
1576         }
1577         _tmp9_ = gee_hazard_pointer_node_new ();
1578         node = _tmp9_;
1579         old_head = NULL;
1580         {
1581                 gboolean _tmp10_;
1582                 _tmp10_ = TRUE;
1583                 while (TRUE) {
1584                         gboolean _tmp11_;
1585                         GeeHazardPointerNode* _tmp15_;
1586                         void* _tmp16_ = NULL;
1587                         GeeHazardPointerNode* _tmp17_;
1588                         _tmp11_ = _tmp10_;
1589                         if (!_tmp11_) {
1590                                 GeeHazardPointerNode* _tmp12_;
1591                                 GeeHazardPointerNode* _tmp13_;
1592                                 gboolean _tmp14_ = FALSE;
1593                                 _tmp12_ = old_head;
1594                                 _tmp13_ = node;
1595                                 _tmp14_ = g_atomic_pointer_compare_and_exchange ((volatile gpointer *) (&gee_hazard_pointer__head), _tmp12_, _tmp13_);
1596                                 if (!(!_tmp14_)) {
1597                                         break;
1598                                 }
1599                         }
1600                         _tmp10_ = FALSE;
1601                         _tmp15_ = node;
1602                         _tmp16_ = g_atomic_pointer_get ((volatile gpointer *) (&gee_hazard_pointer__head));
1603                         old_head = (GeeHazardPointerNode*) _tmp16_;
1604                         _tmp17_ = old_head;
1605                         gee_hazard_pointer_node_set_next (_tmp15_, _tmp17_);
1606                 }
1607         }
1608         _tmp18_ = node;
1609         result = _tmp18_;
1610         return result;
1611 }
1612
1613
1614 /**
1615  * Tries to free from list.
1616  *
1617  * @return ``true`` if list is empty.
1618  */
1619 gboolean gee_hazard_pointer_try_free (GeeArrayList* to_free) {
1620         gboolean result = FALSE;
1621         GeeHashSet* _tmp0_;
1622         GeeCollection* used;
1623         GeeArrayList* _tmp45_;
1624         gint _tmp46_;
1625         gint _tmp47_;
1626         g_return_val_if_fail (to_free != NULL, FALSE);
1627         _tmp0_ = gee_hash_set_new (G_TYPE_POINTER, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1628         used = (GeeCollection*) _tmp0_;
1629         {
1630                 GeeHazardPointerNode* _tmp1_ = NULL;
1631                 GeeHazardPointerNode* current;
1632                 _tmp1_ = gee_hazard_pointer_get_head ();
1633                 current = _tmp1_;
1634                 {
1635                         gboolean _tmp2_;
1636                         _tmp2_ = TRUE;
1637                         while (TRUE) {
1638                                 gboolean _tmp3_;
1639                                 GeeHazardPointerNode* _tmp6_;
1640                                 GeeCollection* _tmp7_;
1641                                 GeeHazardPointerNode* _tmp8_;
1642                                 void* _tmp9_ = NULL;
1643                                 _tmp3_ = _tmp2_;
1644                                 if (!_tmp3_) {
1645                                         GeeHazardPointerNode* _tmp4_;
1646                                         GeeHazardPointerNode* _tmp5_ = NULL;
1647                                         _tmp4_ = current;
1648                                         _tmp5_ = gee_hazard_pointer_node_get_next (_tmp4_);
1649                                         current = _tmp5_;
1650                                 }
1651                                 _tmp2_ = FALSE;
1652                                 _tmp6_ = current;
1653                                 if (!(_tmp6_ != NULL)) {
1654                                         break;
1655                                 }
1656                                 _tmp7_ = used;
1657                                 _tmp8_ = current;
1658                                 _tmp9_ = gee_hazard_pointer_node_get (_tmp8_, TRUE);
1659                                 gee_collection_add (_tmp7_, _tmp9_);
1660                         }
1661                 }
1662         }
1663         {
1664                 gint i;
1665                 i = 0;
1666                 {
1667                         gboolean _tmp10_;
1668                         _tmp10_ = TRUE;
1669                         while (TRUE) {
1670                                 gboolean _tmp11_;
1671                                 gint _tmp12_;
1672                                 GeeArrayList* _tmp13_;
1673                                 gint _tmp14_;
1674                                 gint _tmp15_;
1675                                 GeeArrayList* _tmp16_;
1676                                 gint _tmp17_;
1677                                 gpointer _tmp18_ = NULL;
1678                                 GeeHazardPointerFreeNode* current;
1679                                 GeeCollection* _tmp19_;
1680                                 GeeHazardPointerFreeNode* _tmp20_;
1681                                 void* _tmp21_;
1682                                 gboolean _tmp22_ = FALSE;
1683                                 _tmp11_ = _tmp10_;
1684                                 if (!_tmp11_) {
1685                                 }
1686                                 _tmp10_ = FALSE;
1687                                 _tmp12_ = i;
1688                                 _tmp13_ = to_free;
1689                                 _tmp14_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp13_);
1690                                 _tmp15_ = _tmp14_;
1691                                 if (!(_tmp12_ < _tmp15_)) {
1692                                         break;
1693                                 }
1694                                 _tmp16_ = to_free;
1695                                 _tmp17_ = i;
1696                                 _tmp18_ = gee_abstract_list_get ((GeeAbstractList*) _tmp16_, _tmp17_);
1697                                 current = _tmp18_;
1698                                 _tmp19_ = used;
1699                                 _tmp20_ = current;
1700                                 _tmp21_ = _tmp20_->pointer;
1701                                 _tmp22_ = gee_collection_contains (_tmp19_, _tmp21_);
1702                                 if (_tmp22_) {
1703                                         gint _tmp23_;
1704                                         _tmp23_ = i;
1705                                         i = _tmp23_ + 1;
1706                                 } else {
1707                                         GeeArrayList* _tmp24_;
1708                                         GeeArrayList* _tmp25_;
1709                                         gint _tmp26_;
1710                                         gint _tmp27_;
1711                                         gpointer _tmp28_ = NULL;
1712                                         GeeHazardPointerFreeNode* cur;
1713                                         gint _tmp29_;
1714                                         GeeArrayList* _tmp30_;
1715                                         gint _tmp31_;
1716                                         gint _tmp32_;
1717                                         GeeHazardPointerFreeNode* _tmp40_;
1718                                         GeeHazardPointerDestroyNotify _tmp41_;
1719                                         void* _tmp41__target;
1720                                         GeeHazardPointerFreeNode* _tmp42_;
1721                                         void* _tmp43_;
1722                                         GeeHazardPointerFreeNode* _tmp44_;
1723                                         _tmp24_ = to_free;
1724                                         _tmp25_ = to_free;
1725                                         _tmp26_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp25_);
1726                                         _tmp27_ = _tmp26_;
1727                                         _tmp28_ = gee_abstract_list_remove_at ((GeeAbstractList*) _tmp24_, _tmp27_ - 1);
1728                                         cur = _tmp28_;
1729                                         _tmp29_ = i;
1730                                         _tmp30_ = to_free;
1731                                         _tmp31_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp30_);
1732                                         _tmp32_ = _tmp31_;
1733                                         if (_tmp29_ != _tmp32_) {
1734                                                 GeeArrayList* _tmp33_;
1735                                                 gint _tmp34_;
1736                                                 gpointer _tmp35_ = NULL;
1737                                                 GeeHazardPointerFreeNode* temp;
1738                                                 GeeArrayList* _tmp36_;
1739                                                 gint _tmp37_;
1740                                                 GeeHazardPointerFreeNode* _tmp38_;
1741                                                 GeeHazardPointerFreeNode* _tmp39_;
1742                                                 _tmp33_ = to_free;
1743                                                 _tmp34_ = i;
1744                                                 _tmp35_ = gee_abstract_list_get ((GeeAbstractList*) _tmp33_, _tmp34_);
1745                                                 temp = _tmp35_;
1746                                                 _tmp36_ = to_free;
1747                                                 _tmp37_ = i;
1748                                                 _tmp38_ = cur;
1749                                                 gee_abstract_list_set ((GeeAbstractList*) _tmp36_, _tmp37_, _tmp38_);
1750                                                 _tmp39_ = temp;
1751                                                 cur = _tmp39_;
1752                                         }
1753                                         _tmp40_ = cur;
1754                                         _tmp41_ = _tmp40_->destroy_notify;
1755                                         _tmp41__target = _tmp40_->destroy_notify_target;
1756                                         _tmp42_ = cur;
1757                                         _tmp43_ = _tmp42_->pointer;
1758                                         _tmp41_ (_tmp43_, _tmp41__target);
1759                                         _tmp44_ = cur;
1760                                         gee_hazard_pointer_free_node_free (_tmp44_);
1761                                 }
1762                         }
1763                 }
1764         }
1765         _tmp45_ = to_free;
1766         _tmp46_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp45_);
1767         _tmp47_ = _tmp46_;
1768         result = _tmp47_ > 0;
1769         _g_object_unref0 (used);
1770         return result;
1771 }
1772
1773
1774 /**
1775  * Gets head of hazard pointers.
1776  * @return Hazard pointer head.
1777  */
1778 GeeHazardPointerNode* gee_hazard_pointer_get_head (void) {
1779         GeeHazardPointerNode* result = NULL;
1780         void* _tmp0_ = NULL;
1781         _tmp0_ = g_atomic_pointer_get ((volatile gpointer *) (&gee_hazard_pointer__head));
1782         result = (GeeHazardPointerNode*) _tmp0_;
1783         return result;
1784 }
1785
1786
1787 static Block5Data* block5_data_ref (Block5Data* _data5_) {
1788         g_atomic_int_inc (&_data5_->_ref_count_);
1789         return _data5_;
1790 }
1791
1792
1793 static void block5_data_unref (void * _userdata_) {
1794         Block5Data* _data5_;
1795         _data5_ = (Block5Data*) _userdata_;
1796         if (g_atomic_int_dec_and_test (&_data5_->_ref_count_)) {
1797                 GType g_type;
1798                 GBoxedCopyFunc g_dup_func;
1799                 GDestroyNotify g_destroy_func;
1800                 g_type = _data5_->g_type;
1801                 g_dup_func = _data5_->g_dup_func;
1802                 g_destroy_func = _data5_->g_destroy_func;
1803                 g_slice_free (Block5Data, _data5_);
1804         }
1805 }
1806
1807
1808 static void __lambda36_ (Block5Data* _data5_, void* ptr) {
1809         GType g_type;
1810         GBoxedCopyFunc g_dup_func;
1811         GDestroyNotify g_destroy_func;
1812         void* _tmp0_;
1813         gconstpointer* gptr;
1814         gconstpointer* _tmp1_;
1815         gpointer obj;
1816         g_type = _data5_->g_type;
1817         g_dup_func = _data5_->g_dup_func;
1818         g_destroy_func = _data5_->g_destroy_func;
1819         _tmp0_ = ptr;
1820         gptr = _tmp0_;
1821         _tmp1_ = gptr;
1822         gptr = NULL;
1823         obj = _tmp1_;
1824         _g_destroy_func0 (obj);
1825         obj = NULL;
1826         _g_destroy_func0 (obj);
1827 }
1828
1829
1830 static void ___lambda36__gee_hazard_pointer_destroy_notify (void* ptr, gpointer self) {
1831         __lambda36_ (self, ptr);
1832 }
1833
1834
1835 GeeHazardPointerDestroyNotify gee_hazard_pointer_get_destroy_notify (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, void** result_target, GDestroyNotify* result_target_destroy_notify) {
1836         GeeHazardPointerDestroyNotify result = NULL;
1837         Block5Data* _data5_;
1838         GeeHazardPointerDestroyNotify _tmp0_;
1839         void* _tmp0__target;
1840         GDestroyNotify _tmp0__target_destroy_notify;
1841         _data5_ = g_slice_new0 (Block5Data);
1842         _data5_->_ref_count_ = 1;
1843         _data5_->g_type = g_type;
1844         _data5_->g_dup_func = g_dup_func;
1845         _data5_->g_destroy_func = g_destroy_func;
1846         _tmp0_ = ___lambda36__gee_hazard_pointer_destroy_notify;
1847         _tmp0__target = block5_data_ref (_data5_);
1848         _tmp0__target_destroy_notify = block5_data_unref;
1849         *result_target = _tmp0__target;
1850         *result_target_destroy_notify = _tmp0__target_destroy_notify;
1851         result = _tmp0_;
1852         block5_data_unref (_data5_);
1853         _data5_ = NULL;
1854         return result;
1855 }
1856
1857
1858 static GeeHazardPointerPolicy* _gee_hazard_pointer_policy_dup (GeeHazardPointerPolicy* self) {
1859         GeeHazardPointerPolicy* dup;
1860         dup = g_new0 (GeeHazardPointerPolicy, 1);
1861         memcpy (dup, self, sizeof (GeeHazardPointerPolicy));
1862         return dup;
1863 }
1864
1865
1866 static gpointer __gee_hazard_pointer_policy_dup0 (gpointer self) {
1867         return self ? _gee_hazard_pointer_policy_dup (self) : NULL;
1868 }
1869
1870
1871 GeeHazardPointerContext* gee_hazard_pointer_context_new (GeeHazardPointerPolicy* policy) {
1872         GeeHazardPointerContext* self;
1873         GeeArrayList* _tmp0_;
1874         void* _tmp1_ = NULL;
1875         GeeHazardPointerPolicy* _tmp2_;
1876         self = g_slice_new0 (GeeHazardPointerContext);
1877         gee_hazard_pointer_context_instance_init (self);
1878         _tmp0_ = gee_array_list_new (G_TYPE_POINTER, NULL, NULL, NULL, NULL, NULL);
1879         _g_object_unref0 (self->_to_free);
1880         self->_to_free = _tmp0_;
1881         _tmp1_ = g_static_private_get (&gee_hazard_pointer_context__current_context);
1882         self->_parent = _tmp1_;
1883         g_static_private_set (&gee_hazard_pointer_context__current_context, self, NULL);
1884         _tmp2_ = policy;
1885         if (_tmp2_ == NULL) {
1886                 GeeHazardPointerContext* _tmp3_;
1887                 _tmp3_ = self->_parent;
1888                 if (_tmp3_ == NULL) {
1889                         gint _tmp4_ = 0;
1890                         GeeHazardPointerPolicy _tmp5_;
1891                         GeeHazardPointerPolicy* _tmp6_;
1892                         _tmp4_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer__thread_exit_policy));
1893                         _tmp5_ = (GeeHazardPointerPolicy) _tmp4_;
1894                         _tmp6_ = __gee_hazard_pointer_policy_dup0 (&_tmp5_);
1895                         _g_free0 (self->_policy);
1896                         self->_policy = _tmp6_;
1897                 } else {
1898                         gint _tmp7_ = 0;
1899                         GeeHazardPointerPolicy _tmp8_;
1900                         GeeHazardPointerPolicy* _tmp9_;
1901                         _tmp7_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer__default_policy));
1902                         _tmp8_ = (GeeHazardPointerPolicy) _tmp7_;
1903                         _tmp9_ = __gee_hazard_pointer_policy_dup0 (&_tmp8_);
1904                         _g_free0 (self->_policy);
1905                         self->_policy = _tmp9_;
1906                 }
1907         } else {
1908                 GeeHazardPointerPolicy* _tmp10_;
1909                 GeeHazardPointerPolicy _tmp11_ = 0;
1910                 GeeHazardPointerPolicy* _tmp12_;
1911                 _tmp10_ = policy;
1912                 _tmp11_ = gee_hazard_pointer_policy_to_concrete (*_tmp10_);
1913                 _tmp12_ = __gee_hazard_pointer_policy_dup0 (&_tmp11_);
1914                 _g_free0 (self->_policy);
1915                 self->_policy = _tmp12_;
1916         }
1917         return self;
1918 }
1919
1920
1921 /**
1922  * Tries to free all freed pointer in current context.
1923  */
1924 void gee_hazard_pointer_context_try_free (GeeHazardPointerContext* self) {
1925         GeeArrayList* _tmp0_;
1926         g_return_if_fail (self != NULL);
1927         _tmp0_ = self->_to_free;
1928         gee_hazard_pointer_try_free (_tmp0_);
1929 }
1930
1931
1932 /**
1933  * Ensure that whole context is freed. Plase note that it might block.
1934  */
1935 void gee_hazard_pointer_context_free_all (GeeHazardPointerContext* self) {
1936         g_return_if_fail (self != NULL);
1937         while (TRUE) {
1938                 GeeArrayList* _tmp0_;
1939                 gboolean _tmp1_ = FALSE;
1940                 _tmp0_ = self->_to_free;
1941                 _tmp1_ = gee_hazard_pointer_try_free (_tmp0_);
1942                 if (!_tmp1_) {
1943                         break;
1944                 }
1945                 g_thread_yield ();
1946         }
1947 }
1948
1949
1950 /**
1951  * Tries to push the current context to releaser.
1952  */
1953 void gee_hazard_pointer_context_try_release (GeeHazardPointerContext* self) {
1954         gboolean _tmp0_ = FALSE;
1955         g_return_if_fail (self != NULL);
1956         _tmp0_ = g_static_mutex_trylock (&gee_hazard_pointer__queue_mutex);
1957         if (_tmp0_) {
1958                 GeeQueue* _tmp1_;
1959                 GeeArrayList* _tmp2_;
1960                 GeeArrayList* _tmp3_;
1961                 GeeArrayList* _tmp4_;
1962                 _tmp1_ = gee_hazard_pointer__queue;
1963                 _tmp2_ = self->_to_free;
1964                 self->_to_free = NULL;
1965                 _tmp3_ = _tmp2_;
1966                 gee_queue_offer (_tmp1_, _tmp3_);
1967                 _g_object_unref0 (_tmp3_);
1968                 _tmp4_ = gee_array_list_new (G_TYPE_POINTER, NULL, NULL, NULL, NULL, NULL);
1969                 _g_object_unref0 (self->_to_free);
1970                 self->_to_free = _tmp4_;
1971                 g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
1972         }
1973 }
1974
1975
1976 /**
1977  * Pushes the current context to releaser. Plase note that it might block.
1978  */
1979 void gee_hazard_pointer_context_release (GeeHazardPointerContext* self) {
1980         GeeQueue* _tmp0_;
1981         GeeArrayList* _tmp1_;
1982         GeeArrayList* _tmp2_;
1983         GeeArrayList* _tmp3_;
1984         g_return_if_fail (self != NULL);
1985         g_static_mutex_lock (&gee_hazard_pointer__queue_mutex);
1986         _tmp0_ = gee_hazard_pointer__queue;
1987         _tmp1_ = self->_to_free;
1988         self->_to_free = NULL;
1989         _tmp2_ = _tmp1_;
1990         gee_queue_offer (_tmp0_, _tmp2_);
1991         _g_object_unref0 (_tmp2_);
1992         _tmp3_ = gee_array_list_new (G_TYPE_POINTER, NULL, NULL, NULL, NULL, NULL);
1993         _g_object_unref0 (self->_to_free);
1994         self->_to_free = _tmp3_;
1995         g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
1996 }
1997
1998
1999 /**
2000  * Add pointer to freed array.
2001  */
2002 inline void gee_hazard_pointer_context_release_ptr (GeeHazardPointerContext* self, void* ptr, GeeHazardPointerDestroyNotify notify, void* notify_target, GDestroyNotify notify_target_destroy_notify) {
2003         GeeHazardPointerFreeNode* _tmp0_;
2004         GeeHazardPointerFreeNode* node;
2005         GeeHazardPointerFreeNode* _tmp1_;
2006         void* _tmp2_;
2007         GeeHazardPointerFreeNode* _tmp3_;
2008         GeeHazardPointerDestroyNotify _tmp4_;
2009         void* _tmp4__target;
2010         GDestroyNotify _tmp4__target_destroy_notify;
2011         GeeArrayList* _tmp5_;
2012         GeeHazardPointerFreeNode* _tmp6_;
2013         GeeArrayList* _tmp7_;
2014         gint _tmp8_;
2015         gint _tmp9_;
2016         guint _tmp10_;
2017         g_return_if_fail (self != NULL);
2018         _tmp0_ = gee_hazard_pointer_free_node_new ();
2019         node = _tmp0_;
2020         _tmp1_ = node;
2021         _tmp2_ = ptr;
2022         _tmp1_->pointer = _tmp2_;
2023         _tmp3_ = node;
2024         _tmp4_ = notify;
2025         _tmp4__target = notify_target;
2026         _tmp4__target_destroy_notify = notify_target_destroy_notify;
2027         notify_target_destroy_notify = NULL;
2028         (_tmp3_->destroy_notify_target_destroy_notify == NULL) ? NULL : (_tmp3_->destroy_notify_target_destroy_notify (_tmp3_->destroy_notify_target), NULL);
2029         _tmp3_->destroy_notify = NULL;
2030         _tmp3_->destroy_notify_target = NULL;
2031         _tmp3_->destroy_notify_target_destroy_notify = NULL;
2032         _tmp3_->destroy_notify = _tmp4_;
2033         _tmp3_->destroy_notify_target = _tmp4__target;
2034         _tmp3_->destroy_notify_target_destroy_notify = _tmp4__target_destroy_notify;
2035         _tmp5_ = self->_to_free;
2036         _tmp6_ = node;
2037         gee_abstract_collection_add ((GeeAbstractCollection*) _tmp5_, _tmp6_);
2038         _tmp7_ = self->_to_free;
2039         _tmp8_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp7_);
2040         _tmp9_ = _tmp8_;
2041         _tmp10_ = gee_hazard_pointer_context_THRESHOLD;
2042         if (((guint) _tmp9_) >= _tmp10_) {
2043                 GeeArrayList* _tmp11_;
2044                 _tmp11_ = self->_to_free;
2045                 gee_hazard_pointer_try_free (_tmp11_);
2046         }
2047         (notify_target_destroy_notify == NULL) ? NULL : (notify_target_destroy_notify (notify_target), NULL);
2048         notify = NULL;
2049         notify_target = NULL;
2050         notify_target_destroy_notify = NULL;
2051 }
2052
2053
2054 /**
2055  * Gets current context.
2056  */
2057 inline GeeHazardPointerContext* gee_hazard_pointer_context_get_current_context (void) {
2058         GeeHazardPointerContext* result = NULL;
2059         void* _tmp0_ = NULL;
2060         _tmp0_ = g_static_private_get (&gee_hazard_pointer_context__current_context);
2061         result = _tmp0_;
2062         return result;
2063 }
2064
2065
2066 static void gee_hazard_pointer_context_instance_init (GeeHazardPointerContext * self) {
2067 }
2068
2069
2070 void gee_hazard_pointer_context_free (GeeHazardPointerContext* self) {
2071         GeeArrayList* _tmp0_;
2072         gint _tmp1_;
2073         gint _tmp2_;
2074         gint size;
2075         gboolean clean_parent;
2076         gint _tmp3_;
2077         GeeHazardPointerContext* _tmp18_;
2078         gboolean _tmp19_;
2079         _tmp0_ = self->_to_free;
2080         _tmp1_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp0_);
2081         _tmp2_ = _tmp1_;
2082         size = _tmp2_;
2083         clean_parent = FALSE;
2084         _tmp3_ = size;
2085         if (_tmp3_ > 0) {
2086                 GeeArrayList* remaining = NULL;
2087                 gboolean _tmp4_ = FALSE;
2088                 GeeHazardPointerContext* _tmp5_;
2089                 gboolean _tmp8_;
2090                 GeeArrayList* _tmp13_;
2091                 _tmp5_ = self->_parent;
2092                 if (_tmp5_ == NULL) {
2093                         _tmp4_ = TRUE;
2094                 } else {
2095                         gint _tmp6_;
2096                         guint _tmp7_;
2097                         _tmp6_ = size;
2098                         _tmp7_ = gee_hazard_pointer_context_THRESHOLD;
2099                         _tmp4_ = ((guint) _tmp6_) >= _tmp7_;
2100                 }
2101                 _tmp8_ = _tmp4_;
2102                 if (_tmp8_) {
2103                         GeeHazardPointerPolicy* _tmp9_;
2104                         GeeArrayList* _tmp10_;
2105                         GeeArrayList* _tmp11_ = NULL;
2106                         _tmp9_ = self->_policy;
2107                         _tmp10_ = self->_to_free;
2108                         self->_to_free = NULL;
2109                         _tmp11_ = gee_hazard_pointer_policy_perform (*_tmp9_, _tmp10_);
2110                         _g_object_unref0 (remaining);
2111                         remaining = _tmp11_;
2112                 } else {
2113                         GeeArrayList* _tmp12_;
2114                         _tmp12_ = self->_to_free;
2115                         self->_to_free = NULL;
2116                         _g_object_unref0 (remaining);
2117                         remaining = _tmp12_;
2118                 }
2119                 _tmp13_ = remaining;
2120                 if (_tmp13_ != NULL) {
2121                         GeeHazardPointerContext* _tmp14_;
2122                         GeeHazardPointerContext* _tmp15_;
2123                         GeeArrayList* _tmp16_;
2124                         GeeArrayList* _tmp17_;
2125                         _tmp14_ = self->_parent;
2126                         _vala_assert (_tmp14_ != NULL, "_parent != null");
2127                         _tmp15_ = self->_parent;
2128                         _tmp16_ = _tmp15_->_to_free;
2129                         _tmp17_ = remaining;
2130                         gee_array_list_add_all (_tmp16_, (GeeCollection*) _tmp17_);
2131                         clean_parent = TRUE;
2132                 }
2133                 _g_object_unref0 (remaining);
2134         }
2135         _tmp18_ = self->_parent;
2136         g_static_private_set (&gee_hazard_pointer_context__current_context, _tmp18_, NULL);
2137         _tmp19_ = clean_parent;
2138         if (_tmp19_) {
2139                 GeeHazardPointerContext* _tmp20_;
2140                 GeeArrayList* _tmp21_;
2141                 _tmp20_ = self->_parent;
2142                 _tmp21_ = _tmp20_->_to_free;
2143                 gee_hazard_pointer_try_free (_tmp21_);
2144         }
2145         _g_object_unref0 (self->_to_free);
2146         _g_free0 (self->_policy);
2147         g_slice_free (GeeHazardPointerContext, self);
2148 }
2149
2150
2151 GeeHazardPointerFreeNode* gee_hazard_pointer_free_node_new (void) {
2152         GeeHazardPointerFreeNode* self;
2153         self = g_slice_new0 (GeeHazardPointerFreeNode);
2154         gee_hazard_pointer_free_node_instance_init (self);
2155         return self;
2156 }
2157
2158
2159 static void gee_hazard_pointer_free_node_instance_init (GeeHazardPointerFreeNode * self) {
2160 }
2161
2162
2163 void gee_hazard_pointer_free_node_free (GeeHazardPointerFreeNode* self) {
2164         (self->destroy_notify_target_destroy_notify == NULL) ? NULL : (self->destroy_notify_target_destroy_notify (self->destroy_notify_target), NULL);
2165         self->destroy_notify = NULL;
2166         self->destroy_notify_target = NULL;
2167         self->destroy_notify_target_destroy_notify = NULL;
2168         g_slice_free (GeeHazardPointerFreeNode, self);
2169 }
2170
2171
2172 GeeHazardPointerNode* gee_hazard_pointer_node_new (void) {
2173         GeeHazardPointerNode* self;
2174         self = g_slice_new0 (GeeHazardPointerNode);
2175         gee_hazard_pointer_node_instance_init (self);
2176         g_atomic_pointer_set ((volatile gpointer *) (&self->_hazard), NULL);
2177         g_atomic_int_set ((volatile gint *) (&self->_active), 1);
2178         return self;
2179 }
2180
2181
2182 void gee_hazard_pointer_node_release (GeeHazardPointerNode* self) {
2183         g_return_if_fail (self != NULL);
2184         g_atomic_pointer_set ((volatile gpointer *) (&self->_hazard), NULL);
2185         g_atomic_int_set ((volatile gint *) (&self->_active), 0);
2186 }
2187
2188
2189 inline gboolean gee_hazard_pointer_node_is_active (GeeHazardPointerNode* self) {
2190         gboolean result = FALSE;
2191         gint _tmp0_ = 0;
2192         g_return_val_if_fail (self != NULL, FALSE);
2193         _tmp0_ = g_atomic_int_get ((volatile gint *) (&self->_active));
2194         result = _tmp0_ != 0;
2195         return result;
2196 }
2197
2198
2199 inline gboolean gee_hazard_pointer_node_activate (GeeHazardPointerNode* self) {
2200         gboolean result = FALSE;
2201         gboolean _tmp0_ = FALSE;
2202         g_return_val_if_fail (self != NULL, FALSE);
2203         _tmp0_ = g_atomic_int_compare_and_exchange ((volatile gint *) (&self->_active), 0, 1);
2204         result = _tmp0_;
2205         return result;
2206 }
2207
2208
2209 inline void gee_hazard_pointer_node_set (GeeHazardPointerNode* self, void* ptr) {
2210         void* _tmp0_;
2211         g_return_if_fail (self != NULL);
2212         _tmp0_ = ptr;
2213         g_atomic_pointer_set ((volatile gpointer *) (&self->_hazard), _tmp0_);
2214 }
2215
2216
2217 inline void* gee_hazard_pointer_node_get (GeeHazardPointerNode* self, gboolean safe) {
2218         void* result = NULL;
2219         gboolean _tmp0_;
2220         g_return_val_if_fail (self != NULL, NULL);
2221         _tmp0_ = safe;
2222         if (_tmp0_) {
2223                 void* _tmp1_ = NULL;
2224                 _tmp1_ = g_atomic_pointer_get ((volatile gpointer *) (&self->_hazard));
2225                 result = (void*) _tmp1_;
2226                 return result;
2227         } else {
2228                 void* _tmp2_;
2229                 _tmp2_ = self->_hazard;
2230                 result = (void*) _tmp2_;
2231                 return result;
2232         }
2233 }
2234
2235
2236 inline GeeHazardPointerNode* gee_hazard_pointer_node_get_next (GeeHazardPointerNode* self) {
2237         GeeHazardPointerNode* result = NULL;
2238         void* _tmp0_ = NULL;
2239         g_return_val_if_fail (self != NULL, NULL);
2240         _tmp0_ = g_atomic_pointer_get ((volatile gpointer *) (&self->_next));
2241         result = (GeeHazardPointerNode*) _tmp0_;
2242         return result;
2243 }
2244
2245
2246 inline void gee_hazard_pointer_node_set_next (GeeHazardPointerNode* self, GeeHazardPointerNode* next) {
2247         GeeHazardPointerNode* _tmp0_;
2248         g_return_if_fail (self != NULL);
2249         _tmp0_ = next;
2250         g_atomic_pointer_set ((volatile gpointer *) (&self->_next), _tmp0_);
2251 }
2252
2253
2254 static void gee_hazard_pointer_node_instance_init (GeeHazardPointerNode * self) {
2255 }
2256
2257
2258 void gee_hazard_pointer_node_free (GeeHazardPointerNode* self) {
2259         GeeHazardPointerNode* _tmp0_;
2260         _tmp0_ = self->_next;
2261         gee_hazard_pointer_node_free (_tmp0_);
2262         g_slice_free (GeeHazardPointerNode, self);
2263 }
2264
2265
2266 static void gee_hazard_pointer_instance_init (GeeHazardPointer * self) {
2267 }
2268
2269
2270 void gee_hazard_pointer_free (GeeHazardPointer* self) {
2271         GeeHazardPointerNode* _tmp0_;
2272         _tmp0_ = self->_node;
2273         gee_hazard_pointer_node_release (_tmp0_);
2274         g_slice_free (GeeHazardPointer, self);
2275 }
2276
2277
2278