1 /* lazy.c generated by valac 0.46.6, the Vala compiler
2  * generated from lazy.vala, do not modify */
3 
4 /* lazy.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 <gio/gio.h>
29 #include <string.h>
30 #include <async.h>
31 #include <gobject/gvaluecollector.h>
32 
33 typedef gpointer (*GeeLazyFunc) (gpointer user_data);
34 
35 #define GEE_TYPE_LAZY (gee_lazy_get_type ())
36 #define GEE_LAZY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_LAZY, GeeLazy))
37 #define GEE_LAZY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_LAZY, GeeLazyClass))
38 #define GEE_IS_LAZY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_LAZY))
39 #define GEE_IS_LAZY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_LAZY))
40 #define GEE_LAZY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_LAZY, GeeLazyClass))
41 
42 typedef struct _GeeLazy GeeLazy;
43 typedef struct _GeeLazyClass GeeLazyClass;
44 typedef struct _GeeLazyPrivate GeeLazyPrivate;
45 #define _g_destroy_func0(var) (((var == NULL) || (g_destroy_func == NULL)) ? NULL : (var = (g_destroy_func (var), NULL)))
46 
47 #define GEE_TYPE_FUTURE (gee_future_get_type ())
48 #define GEE_FUTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_FUTURE, GeeFuture))
49 #define GEE_IS_FUTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_FUTURE))
50 #define GEE_FUTURE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_FUTURE, GeeFutureIface))
51 
52 typedef struct _GeeFuture GeeFuture;
53 typedef struct _GeeFutureIface GeeFutureIface;
54 typedef gpointer (*GeeFutureMapFunc) (gconstpointer value, gpointer user_data);
55 typedef gconstpointer (*GeeFutureLightMapFunc) (gconstpointer value, gpointer user_data);
56 typedef gpointer (*GeeFutureZipFunc) (gconstpointer a, gconstpointer b, gpointer user_data);
57 typedef GeeFuture* (*GeeFutureFlatMapFunc) (gconstpointer value, gpointer user_data);
58 
59 #define GEE_LAZY_TYPE_FUTURE (gee_lazy_future_get_type ())
60 #define GEE_LAZY_FUTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_LAZY_TYPE_FUTURE, GeeLazyFuture))
61 #define GEE_LAZY_FUTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_LAZY_TYPE_FUTURE, GeeLazyFutureClass))
62 #define GEE_LAZY_IS_FUTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_LAZY_TYPE_FUTURE))
63 #define GEE_LAZY_IS_FUTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_LAZY_TYPE_FUTURE))
64 #define GEE_LAZY_FUTURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_LAZY_TYPE_FUTURE, GeeLazyFutureClass))
65 
66 typedef struct _GeeLazyFuture GeeLazyFuture;
67 typedef struct _GeeLazyFutureClass GeeLazyFutureClass;
68 typedef struct _GeeLazyFuturePrivate GeeLazyFuturePrivate;
69 typedef enum  {
70 	GEE_LAZY_FUTURE_STATE_UNLOCK,
71 	GEE_LAZY_FUTURE_STATE_EVAL
72 } GeeLazyFutureState;
73 
74 #define GEE_LAZY_FUTURE_TYPE_STATE (gee_lazy_future_state_get_type ())
75 
76 #define GEE_FUTURE_TYPE_SOURCE_FUNC_ARRAY_ELEMENT (gee_future_source_func_array_element_get_type ())
77 typedef struct _GeeFutureSourceFuncArrayElement GeeFutureSourceFuncArrayElement;
78 enum  {
79 	GEE_LAZY_FUTURE_0_PROPERTY,
80 	GEE_LAZY_FUTURE_G_TYPE,
81 	GEE_LAZY_FUTURE_G_DUP_FUNC,
82 	GEE_LAZY_FUTURE_G_DESTROY_FUNC,
83 	GEE_LAZY_FUTURE_READY_PROPERTY,
84 	GEE_LAZY_FUTURE_EXCEPTION_PROPERTY,
85 	GEE_LAZY_FUTURE_NUM_PROPERTIES
86 };
87 static GParamSpec* gee_lazy_future_properties[GEE_LAZY_FUTURE_NUM_PROPERTIES];
88 #define _gee_lazy_unref0(var) ((var == NULL) ? NULL : (var = (gee_lazy_unref (var), NULL)))
89 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
90 typedef struct _GeeLazyFutureWaitAsyncData GeeLazyFutureWaitAsyncData;
91 typedef struct _GeeParamSpecLazy GeeParamSpecLazy;
92 
93 struct _GeeLazy {
94 	GTypeInstance parent_instance;
95 	volatile int ref_count;
96 	GeeLazyPrivate * priv;
97 };
98 
99 struct _GeeLazyClass {
100 	GTypeClass parent_class;
101 	void (*finalize) (GeeLazy *self);
102 };
103 
104 struct _GeeLazyPrivate {
105 	GType g_type;
106 	GBoxedCopyFunc g_dup_func;
107 	GDestroyNotify g_destroy_func;
108 	GeeLazyFunc _func;
109 	gpointer _func_target;
110 	GDestroyNotify _func_target_destroy_notify;
111 	gpointer _value;
112 };
113 
114 typedef enum  {
115 	GEE_FUTURE_ERROR_ABANDON_PROMISE,
116 	GEE_FUTURE_ERROR_EXCEPTION
117 } GeeFutureError;
118 #define GEE_FUTURE_ERROR gee_future_error_quark ()
119 struct _GeeFutureIface {
120 	GTypeInterface parent_iface;
121 	GType (*get_g_type) (GeeFuture* self);
122 	GBoxedCopyFunc (*get_g_dup_func) (GeeFuture* self);
123 	GDestroyNotify (*get_g_destroy_func) (GeeFuture* self);
124 	gconstpointer (*wait) (GeeFuture* self, GError** error);
125 	gboolean (*wait_until) (GeeFuture* self, gint64 end_time, gconstpointer* value, GError** error);
126 	void (*wait_async) (GeeFuture* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
127 	gconstpointer (*wait_finish) (GeeFuture* self, GAsyncResult* _res_, GError** error);
128 	GeeFuture* (*map) (GeeFuture* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFutureMapFunc func, gpointer func_target, GDestroyNotify func_target_destroy_notify);
129 	GeeFuture* (*light_map) (GeeFuture* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFutureLightMapFunc func, gpointer func_target);
130 	GeeFuture* (*zip) (GeeFuture* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GType b_type, GBoxedCopyFunc b_dup_func, GDestroyNotify b_destroy_func, GeeFutureZipFunc zip_func, gpointer zip_func_target, GeeFuture* second);
131 	GeeFuture* (*flat_map) (GeeFuture* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFutureFlatMapFunc func, gpointer func_target, GDestroyNotify func_target_destroy_notify);
132 	gconstpointer (*get_value) (GeeFuture* self);
133 	gboolean (*get_ready) (GeeFuture* self);
134 	GError* (*get_exception) (GeeFuture* self);
135 	GeeFuture* (*light_map_fixed) (GeeFuture* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFutureLightMapFunc func, gpointer func_target, GDestroyNotify func_target_destroy_notify);
136 };
137 
138 struct _GeeLazyFuture {
139 	GObject parent_instance;
140 	GeeLazyFuturePrivate * priv;
141 };
142 
143 struct _GeeLazyFutureClass {
144 	GObjectClass parent_class;
145 };
146 
147 struct _GeeFutureSourceFuncArrayElement {
148 	GSourceFunc func;
149 	gpointer func_target;
150 	GDestroyNotify func_target_destroy_notify;
151 };
152 
153 struct _GeeLazyFuturePrivate {
154 	GType g_type;
155 	GBoxedCopyFunc g_dup_func;
156 	GDestroyNotify g_destroy_func;
157 	GMutex _mutex;
158 	GCond _eval;
159 	GeeLazy* _lazy;
160 	GeeLazyFutureState _state;
161 	GeeFutureSourceFuncArrayElement* _when_done;
162 	gint _when_done_length1;
163 	gint __when_done_size_;
164 };
165 
166 struct _GeeLazyFutureWaitAsyncData {
167 	int _state_;
168 	GObject* _source_object_;
169 	GAsyncResult* _res_;
170 	GTask* _async_result;
171 	GeeLazyFuture* self;
172 	gconstpointer result;
173 	GeeLazy* _tmp0_;
174 	GeeLazyFunc _tmp1_;
175 	gpointer _tmp1__target;
176 	GeeLazyFutureState _tmp2_;
177 	GeeFutureSourceFuncArrayElement* _tmp3_;
178 	gint _tmp3__length1;
179 	GeeFutureSourceFuncArrayElement _tmp4_;
180 	GeeLazy* _tmp5_;
181 	gconstpointer _tmp6_;
182 	gconstpointer _tmp7_;
183 };
184 
185 struct _GeeParamSpecLazy {
186 	GParamSpec parent_instance;
187 };
188 
189 static gint GeeLazy_private_offset;
190 static gpointer gee_lazy_parent_class = NULL;
191 static gint GeeLazyFuture_private_offset;
192 static gpointer gee_lazy_future_parent_class = NULL;
193 static GeeFutureIface * gee_lazy_future_gee_future_parent_iface = NULL;
194 
195 gpointer gee_lazy_ref (gpointer instance);
196 void gee_lazy_unref (gpointer instance);
197 GParamSpec* gee_param_spec_lazy (const gchar* name,
198                                  const gchar* nick,
199                                  const gchar* blurb,
200                                  GType object_type,
201                                  GParamFlags flags);
202 void gee_value_set_lazy (GValue* value,
203                          gpointer v_object);
204 void gee_value_take_lazy (GValue* value,
205                           gpointer v_object);
206 gpointer gee_value_get_lazy (const GValue* value);
207 GType gee_lazy_get_type (void) G_GNUC_CONST;
208 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GeeLazy, gee_lazy_unref)
209 GeeLazy* gee_lazy_new (GType g_type,
210                        GBoxedCopyFunc g_dup_func,
211                        GDestroyNotify g_destroy_func,
212                        GeeLazyFunc func,
213                        gpointer func_target,
214                        GDestroyNotify func_target_destroy_notify);
215 GeeLazy* gee_lazy_construct (GType object_type,
216                              GType g_type,
217                              GBoxedCopyFunc g_dup_func,
218                              GDestroyNotify g_destroy_func,
219                              GeeLazyFunc func,
220                              gpointer func_target,
221                              GDestroyNotify func_target_destroy_notify);
222 GeeLazy* gee_lazy_new_from_value (GType g_type,
223                                   GBoxedCopyFunc g_dup_func,
224                                   GDestroyNotify g_destroy_func,
225                                   gconstpointer item);
226 GeeLazy* gee_lazy_construct_from_value (GType object_type,
227                                         GType g_type,
228                                         GBoxedCopyFunc g_dup_func,
229                                         GDestroyNotify g_destroy_func,
230                                         gconstpointer item);
231 void gee_lazy_eval (GeeLazy* self);
232 gpointer gee_lazy_get (GeeLazy* self);
233 gconstpointer gee_lazy_get_value (GeeLazy* self);
234 GQuark gee_future_error_quark (void);
235 GType gee_future_get_type (void) G_GNUC_CONST;
236 GeeFuture* gee_lazy_get_future (GeeLazy* self);
237 static GeeLazyFuture* gee_lazy_future_new (GType g_type,
238                                     GBoxedCopyFunc g_dup_func,
239                                     GDestroyNotify g_destroy_func,
240                                     GeeLazy* lazy);
241 static GeeLazyFuture* gee_lazy_future_construct (GType object_type,
242                                           GType g_type,
243                                           GBoxedCopyFunc g_dup_func,
244                                           GDestroyNotify g_destroy_func,
245                                           GeeLazy* lazy);
246 static GType gee_lazy_future_get_type (void) G_GNUC_CONST G_GNUC_UNUSED;
247 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GeeLazyFuture, g_object_unref)
248 static GType gee_lazy_future_state_get_type (void) G_GNUC_CONST G_GNUC_UNUSED;
249 G_GNUC_INTERNAL GType gee_future_source_func_array_element_get_type (void) G_GNUC_CONST G_GNUC_UNUSED;
250 G_GNUC_INTERNAL GeeFutureSourceFuncArrayElement* gee_future_source_func_array_element_dup (const GeeFutureSourceFuncArrayElement* self);
251 G_GNUC_INTERNAL void gee_future_source_func_array_element_free (GeeFutureSourceFuncArrayElement* self);
252 G_GNUC_INTERNAL void gee_future_source_func_array_element_copy (const GeeFutureSourceFuncArrayElement* self,
253                                                 GeeFutureSourceFuncArrayElement* dest);
254 G_GNUC_INTERNAL void gee_future_source_func_array_element_destroy (GeeFutureSourceFuncArrayElement* self);
255 static void _vala_GeeFutureSourceFuncArrayElement_array_free (GeeFutureSourceFuncArrayElement * array,
256                                                        gint array_length);
257 static gconstpointer gee_lazy_future_real_wait (GeeFuture* base,
258                                          GError** error);
259 static void gee_lazy_future_do_eval (GeeLazyFuture* self);
260 static gboolean gee_lazy_future_real_wait_until (GeeFuture* base,
261                                           gint64 end_time,
262                                           gconstpointer* value,
263                                           GError** error);
264 static void gee_lazy_future_real_wait_async_data_free (gpointer _data);
265 static void gee_lazy_future_real_wait_async (GeeFuture* base,
266                                       GAsyncReadyCallback _callback_,
267                                       gpointer _user_data_);
268 static gboolean gee_lazy_future_real_wait_async_co (GeeLazyFutureWaitAsyncData* _data_);
269 void gee_future_wait_async (GeeFuture* self,
270                             GAsyncReadyCallback _callback_,
271                             gpointer _user_data_);
272 gconstpointer gee_future_wait_finish (GeeFuture* self,
273                                       GAsyncResult* _res_,
274                                       GError** error);
275 static gboolean _gee_lazy_future_real_wait_async_co_gsource_func (gpointer self);
276 G_GNUC_INTERNAL void gee_future_source_func_array_element_init (GeeFutureSourceFuncArrayElement *self,
277                                                 GSourceFunc func,
278                                                 gpointer func_target,
279                                                 GDestroyNotify func_target_destroy_notify);
280 static void _vala_array_add1 (GeeFutureSourceFuncArrayElement* * array,
281                        int* length,
282                        int* size,
283                        const GeeFutureSourceFuncArrayElement* value);
284 static void gee_lazy_future_wait_async_ready (GObject* source_object,
285                                        GAsyncResult* _res_,
286                                        gpointer _user_data_);
287 static void gee_lazy_future_finalize (GObject * obj);
288 gboolean gee_future_get_ready (GeeFuture* self);
289 GError* gee_future_get_exception (GeeFuture* self);
290 static void _vala_gee_lazy_future_get_property (GObject * object,
291                                          guint property_id,
292                                          GValue * value,
293                                          GParamSpec * pspec);
294 static void _vala_gee_lazy_future_set_property (GObject * object,
295                                          guint property_id,
296                                          const GValue * value,
297                                          GParamSpec * pspec);
298 static void gee_lazy_finalize (GeeLazy * obj);
299 static void _vala_clear_GMutex (GMutex * mutex);
300 static void _vala_clear_GRecMutex (GRecMutex * mutex);
301 static void _vala_clear_GRWLock (GRWLock * mutex);
302 static void _vala_clear_GCond (GCond * mutex);
303 
304 static inline gpointer
gee_lazy_get_instance_private(GeeLazy * self)305 gee_lazy_get_instance_private (GeeLazy* self)
306 {
307 	return G_STRUCT_MEMBER_P (self, GeeLazy_private_offset);
308 }
309 
310 GeeLazy*
gee_lazy_construct(GType object_type,GType g_type,GBoxedCopyFunc g_dup_func,GDestroyNotify g_destroy_func,GeeLazyFunc func,gpointer func_target,GDestroyNotify func_target_destroy_notify)311 gee_lazy_construct (GType object_type,
312                     GType g_type,
313                     GBoxedCopyFunc g_dup_func,
314                     GDestroyNotify g_destroy_func,
315                     GeeLazyFunc func,
316                     gpointer func_target,
317                     GDestroyNotify func_target_destroy_notify)
318 {
319 	GeeLazy* self = NULL;
320 	GeeLazyFunc _tmp0_;
321 	gpointer _tmp0__target;
322 	GDestroyNotify _tmp0__target_destroy_notify;
323 	self = (GeeLazy*) g_type_create_instance (object_type);
324 	self->priv->g_type = g_type;
325 	self->priv->g_dup_func = g_dup_func;
326 	self->priv->g_destroy_func = g_destroy_func;
327 	_tmp0_ = func;
328 	_tmp0__target = func_target;
329 	_tmp0__target_destroy_notify = func_target_destroy_notify;
330 	func = NULL;
331 	func_target = NULL;
332 	func_target_destroy_notify = NULL;
333 	(self->priv->_func_target_destroy_notify == NULL) ? NULL : (self->priv->_func_target_destroy_notify (self->priv->_func_target), NULL);
334 	self->priv->_func = NULL;
335 	self->priv->_func_target = NULL;
336 	self->priv->_func_target_destroy_notify = NULL;
337 	self->priv->_func = _tmp0_;
338 	self->priv->_func_target = _tmp0__target;
339 	self->priv->_func_target_destroy_notify = _tmp0__target_destroy_notify;
340 	(func_target_destroy_notify == NULL) ? NULL : (func_target_destroy_notify (func_target), NULL);
341 	func = NULL;
342 	func_target = NULL;
343 	func_target_destroy_notify = NULL;
344 	return self;
345 }
346 
347 GeeLazy*
gee_lazy_new(GType g_type,GBoxedCopyFunc g_dup_func,GDestroyNotify g_destroy_func,GeeLazyFunc func,gpointer func_target,GDestroyNotify func_target_destroy_notify)348 gee_lazy_new (GType g_type,
349               GBoxedCopyFunc g_dup_func,
350               GDestroyNotify g_destroy_func,
351               GeeLazyFunc func,
352               gpointer func_target,
353               GDestroyNotify func_target_destroy_notify)
354 {
355 	return gee_lazy_construct (GEE_TYPE_LAZY, g_type, g_dup_func, g_destroy_func, func, func_target, func_target_destroy_notify);
356 }
357 
358 GeeLazy*
gee_lazy_construct_from_value(GType object_type,GType g_type,GBoxedCopyFunc g_dup_func,GDestroyNotify g_destroy_func,gconstpointer item)359 gee_lazy_construct_from_value (GType object_type,
360                                GType g_type,
361                                GBoxedCopyFunc g_dup_func,
362                                GDestroyNotify g_destroy_func,
363                                gconstpointer item)
364 {
365 	GeeLazy* self = NULL;
366 	gpointer _tmp0_;
367 	self = (GeeLazy*) g_type_create_instance (object_type);
368 	self->priv->g_type = g_type;
369 	self->priv->g_dup_func = g_dup_func;
370 	self->priv->g_destroy_func = g_destroy_func;
371 	_tmp0_ = ((item != NULL) && (g_dup_func != NULL)) ? g_dup_func ((gpointer) item) : ((gpointer) item);
372 	_g_destroy_func0 (self->priv->_value);
373 	self->priv->_value = _tmp0_;
374 	return self;
375 }
376 
377 GeeLazy*
gee_lazy_new_from_value(GType g_type,GBoxedCopyFunc g_dup_func,GDestroyNotify g_destroy_func,gconstpointer item)378 gee_lazy_new_from_value (GType g_type,
379                          GBoxedCopyFunc g_dup_func,
380                          GDestroyNotify g_destroy_func,
381                          gconstpointer item)
382 {
383 	return gee_lazy_construct_from_value (GEE_TYPE_LAZY, g_type, g_dup_func, g_destroy_func, item);
384 }
385 
386 void
gee_lazy_eval(GeeLazy * self)387 gee_lazy_eval (GeeLazy* self)
388 {
389 	GeeLazyFunc _tmp0_;
390 	gpointer _tmp0__target;
391 	g_return_if_fail (self != NULL);
392 	_tmp0_ = self->priv->_func;
393 	_tmp0__target = self->priv->_func_target;
394 	if (_tmp0_ != NULL) {
395 		GeeLazyFunc _tmp1_;
396 		gpointer _tmp1__target;
397 		gpointer _tmp2_;
398 		_tmp1_ = self->priv->_func;
399 		_tmp1__target = self->priv->_func_target;
400 		_tmp2_ = _tmp1_ (_tmp1__target);
401 		((self->priv->_value == NULL) || (self->priv->g_destroy_func == NULL)) ? NULL : (self->priv->_value = (self->priv->g_destroy_func (self->priv->_value), NULL));
402 		self->priv->_value = _tmp2_;
403 		(self->priv->_func_target_destroy_notify == NULL) ? NULL : (self->priv->_func_target_destroy_notify (self->priv->_func_target), NULL);
404 		self->priv->_func = NULL;
405 		self->priv->_func_target = NULL;
406 		self->priv->_func_target_destroy_notify = NULL;
407 		self->priv->_func = NULL;
408 		self->priv->_func_target = NULL;
409 		self->priv->_func_target_destroy_notify = NULL;
410 	}
411 }
412 
413 gpointer
gee_lazy_get(GeeLazy * self)414 gee_lazy_get (GeeLazy* self)
415 {
416 	gconstpointer _tmp0_;
417 	gpointer _tmp1_;
418 	gpointer result = NULL;
419 	g_return_val_if_fail (self != NULL, NULL);
420 	gee_lazy_eval (self);
421 	_tmp0_ = self->priv->_value;
422 	_tmp1_ = ((_tmp0_ != NULL) && (self->priv->g_dup_func != NULL)) ? self->priv->g_dup_func ((gpointer) _tmp0_) : ((gpointer) _tmp0_);
423 	result = _tmp1_;
424 	return result;
425 }
426 
427 gconstpointer
gee_lazy_get_value(GeeLazy * self)428 gee_lazy_get_value (GeeLazy* self)
429 {
430 	gconstpointer result;
431 	gconstpointer _tmp0_;
432 	g_return_val_if_fail (self != NULL, NULL);
433 	gee_lazy_eval (self);
434 	_tmp0_ = self->priv->_value;
435 	result = _tmp0_;
436 	return result;
437 }
438 
439 GeeFuture*
gee_lazy_get_future(GeeLazy * self)440 gee_lazy_get_future (GeeLazy* self)
441 {
442 	GeeFuture* result;
443 	GeeLazyFuture* _tmp0_;
444 	g_return_val_if_fail (self != NULL, NULL);
445 	_tmp0_ = gee_lazy_future_new (self->priv->g_type, (GBoxedCopyFunc) self->priv->g_dup_func, (GDestroyNotify) self->priv->g_destroy_func, self);
446 	result = (GeeFuture*) _tmp0_;
447 	return result;
448 }
449 
450 static inline gpointer
gee_lazy_future_get_instance_private(GeeLazyFuture * self)451 gee_lazy_future_get_instance_private (GeeLazyFuture* self)
452 {
453 	return G_STRUCT_MEMBER_P (self, GeeLazyFuture_private_offset);
454 }
455 
456 static GType
gee_lazy_future_state_get_type(void)457 gee_lazy_future_state_get_type (void)
458 {
459 	static volatile gsize gee_lazy_future_state_type_id__volatile = 0;
460 	if (g_once_init_enter (&gee_lazy_future_state_type_id__volatile)) {
461 		static const GEnumValue values[] = {{GEE_LAZY_FUTURE_STATE_UNLOCK, "GEE_LAZY_FUTURE_STATE_UNLOCK", "unlock"}, {GEE_LAZY_FUTURE_STATE_EVAL, "GEE_LAZY_FUTURE_STATE_EVAL", "eval"}, {0, NULL, NULL}};
462 		GType gee_lazy_future_state_type_id;
463 		gee_lazy_future_state_type_id = g_enum_register_static ("GeeLazyFutureState", values);
464 		g_once_init_leave (&gee_lazy_future_state_type_id__volatile, gee_lazy_future_state_type_id);
465 	}
466 	return gee_lazy_future_state_type_id__volatile;
467 }
468 
469 static void
_vala_GeeFutureSourceFuncArrayElement_array_free(GeeFutureSourceFuncArrayElement * array,gint array_length)470 _vala_GeeFutureSourceFuncArrayElement_array_free (GeeFutureSourceFuncArrayElement * array,
471                                                   gint array_length)
472 {
473 	if (array != NULL) {
474 		int i;
475 		for (i = 0; i < array_length; i = i + 1) {
476 			gee_future_source_func_array_element_destroy (&array[i]);
477 		}
478 	}
479 	g_free (array);
480 }
481 
482 static gpointer
_gee_lazy_ref0(gpointer self)483 _gee_lazy_ref0 (gpointer self)
484 {
485 	return self ? gee_lazy_ref (self) : NULL;
486 }
487 
488 static GeeLazyFuture*
gee_lazy_future_construct(GType object_type,GType g_type,GBoxedCopyFunc g_dup_func,GDestroyNotify g_destroy_func,GeeLazy * lazy)489 gee_lazy_future_construct (GType object_type,
490                            GType g_type,
491                            GBoxedCopyFunc g_dup_func,
492                            GDestroyNotify g_destroy_func,
493                            GeeLazy* lazy)
494 {
495 	GeeLazyFuture * self = NULL;
496 	GeeLazy* _tmp0_;
497 	GeeFutureSourceFuncArrayElement* _tmp1_;
498 	g_return_val_if_fail (lazy != NULL, NULL);
499 	self = (GeeLazyFuture*) g_object_new (object_type, NULL);
500 	self->priv->g_type = g_type;
501 	self->priv->g_dup_func = g_dup_func;
502 	self->priv->g_destroy_func = g_destroy_func;
503 	_tmp0_ = _gee_lazy_ref0 (lazy);
504 	_gee_lazy_unref0 (self->priv->_lazy);
505 	self->priv->_lazy = _tmp0_;
506 	_tmp1_ = g_new0 (GeeFutureSourceFuncArrayElement, 0);
507 	self->priv->_when_done = (_vala_GeeFutureSourceFuncArrayElement_array_free (self->priv->_when_done, self->priv->_when_done_length1), NULL);
508 	self->priv->_when_done = _tmp1_;
509 	self->priv->_when_done_length1 = 0;
510 	self->priv->__when_done_size_ = self->priv->_when_done_length1;
511 	return self;
512 }
513 
514 static GeeLazyFuture*
gee_lazy_future_new(GType g_type,GBoxedCopyFunc g_dup_func,GDestroyNotify g_destroy_func,GeeLazy * lazy)515 gee_lazy_future_new (GType g_type,
516                      GBoxedCopyFunc g_dup_func,
517                      GDestroyNotify g_destroy_func,
518                      GeeLazy* lazy)
519 {
520 	return gee_lazy_future_construct (GEE_LAZY_TYPE_FUTURE, g_type, g_dup_func, g_destroy_func, lazy);
521 }
522 
523 static gconstpointer
gee_lazy_future_real_wait(GeeFuture * base,GError ** error)524 gee_lazy_future_real_wait (GeeFuture* base,
525                            GError** error)
526 {
527 	GeeLazyFuture * self;
528 	GeeLazy* _tmp0_;
529 	GeeLazyFunc _tmp1_;
530 	gpointer _tmp1__target;
531 	GeeLazy* _tmp4_;
532 	gconstpointer _tmp5_;
533 	gconstpointer result = NULL;
534 	self = (GeeLazyFuture*) base;
535 	g_mutex_lock (&self->priv->_mutex);
536 	_tmp0_ = self->priv->_lazy;
537 	_tmp1_ = _tmp0_->priv->_func;
538 	_tmp1__target = _tmp0_->priv->_func_target;
539 	if (_tmp1_ != NULL) {
540 		GeeLazyFutureState _tmp2_;
541 		_tmp2_ = self->priv->_state;
542 		if (_tmp2_ == GEE_LAZY_FUTURE_STATE_EVAL) {
543 			while (TRUE) {
544 				GeeLazyFutureState _tmp3_;
545 				_tmp3_ = self->priv->_state;
546 				if (!(_tmp3_ == GEE_LAZY_FUTURE_STATE_EVAL)) {
547 					break;
548 				}
549 				g_cond_wait (&self->priv->_eval, &self->priv->_mutex);
550 			}
551 			g_mutex_unlock (&self->priv->_mutex);
552 		} else {
553 			gee_lazy_future_do_eval (self);
554 		}
555 	} else {
556 		g_mutex_unlock (&self->priv->_mutex);
557 	}
558 	_tmp4_ = self->priv->_lazy;
559 	_tmp5_ = _tmp4_->priv->_value;
560 	result = _tmp5_;
561 	return result;
562 }
563 
564 static gboolean
gee_lazy_future_real_wait_until(GeeFuture * base,gint64 end_time,gconstpointer * value,GError ** error)565 gee_lazy_future_real_wait_until (GeeFuture* base,
566                                  gint64 end_time,
567                                  gconstpointer* value,
568                                  GError** error)
569 {
570 	GeeLazyFuture * self;
571 	gconstpointer _vala_value = NULL;
572 	GeeLazy* _tmp0_;
573 	GeeLazyFunc _tmp1_;
574 	gpointer _tmp1__target;
575 	GeeLazy* _tmp4_;
576 	gconstpointer _tmp5_;
577 	gboolean result = FALSE;
578 	self = (GeeLazyFuture*) base;
579 	g_mutex_lock (&self->priv->_mutex);
580 	_tmp0_ = self->priv->_lazy;
581 	_tmp1_ = _tmp0_->priv->_func;
582 	_tmp1__target = _tmp0_->priv->_func_target;
583 	if (_tmp1_ != NULL) {
584 		GeeLazyFutureState _tmp2_;
585 		_tmp2_ = self->priv->_state;
586 		if (_tmp2_ == GEE_LAZY_FUTURE_STATE_EVAL) {
587 			gboolean res = FALSE;
588 			res = TRUE;
589 			while (TRUE) {
590 				GeeLazyFutureState _tmp3_;
591 				_tmp3_ = self->priv->_state;
592 				if (!(_tmp3_ == GEE_LAZY_FUTURE_STATE_EVAL)) {
593 					break;
594 				}
595 				res = g_cond_wait_until (&self->priv->_eval, &self->priv->_mutex, end_time);
596 				if (!res) {
597 					break;
598 				}
599 			}
600 			g_mutex_unlock (&self->priv->_mutex);
601 			if (!res) {
602 				_vala_value = NULL;
603 				result = FALSE;
604 				if (value) {
605 					*value = _vala_value;
606 				}
607 				return result;
608 			}
609 		} else {
610 			gee_lazy_future_do_eval (self);
611 		}
612 	} else {
613 		g_mutex_unlock (&self->priv->_mutex);
614 	}
615 	_tmp4_ = self->priv->_lazy;
616 	_tmp5_ = _tmp4_->priv->_value;
617 	_vala_value = _tmp5_;
618 	result = TRUE;
619 	if (value) {
620 		*value = _vala_value;
621 	}
622 	return result;
623 }
624 
625 static void
gee_lazy_future_real_wait_async_data_free(gpointer _data)626 gee_lazy_future_real_wait_async_data_free (gpointer _data)
627 {
628 	GeeLazyFutureWaitAsyncData* _data_;
629 	_data_ = _data;
630 	_g_object_unref0 (_data_->self);
631 	g_slice_free (GeeLazyFutureWaitAsyncData, _data_);
632 }
633 
634 static gpointer
_g_object_ref0(gpointer self)635 _g_object_ref0 (gpointer self)
636 {
637 	return self ? g_object_ref (self) : NULL;
638 }
639 
640 static void
gee_lazy_future_real_wait_async(GeeFuture * base,GAsyncReadyCallback _callback_,gpointer _user_data_)641 gee_lazy_future_real_wait_async (GeeFuture* base,
642                                  GAsyncReadyCallback _callback_,
643                                  gpointer _user_data_)
644 {
645 	GeeLazyFuture * self;
646 	GeeLazyFutureWaitAsyncData* _data_;
647 	GeeLazyFuture* _tmp0_;
648 	self = (GeeLazyFuture*) base;
649 	_data_ = g_slice_new0 (GeeLazyFutureWaitAsyncData);
650 	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
651 	g_task_set_task_data (_data_->_async_result, _data_, gee_lazy_future_real_wait_async_data_free);
652 	_tmp0_ = _g_object_ref0 (self);
653 	_data_->self = _tmp0_;
654 	gee_lazy_future_real_wait_async_co (_data_);
655 }
656 
657 static gconstpointer
gee_lazy_future_wait_finish(GeeFuture * base,GAsyncResult * _res_,GError ** error)658 gee_lazy_future_wait_finish (GeeFuture* base,
659                              GAsyncResult* _res_,
660                              GError** error)
661 {
662 	gconstpointer result;
663 	GeeLazyFutureWaitAsyncData* _data_;
664 	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
665 	if (NULL == _data_) {
666 		return NULL;
667 	}
668 	result = _data_->result;
669 	_data_->result = NULL;
670 	return result;
671 }
672 
673 static gboolean
_gee_lazy_future_real_wait_async_co_gsource_func(gpointer self)674 _gee_lazy_future_real_wait_async_co_gsource_func (gpointer self)
675 {
676 	gboolean result;
677 	result = gee_lazy_future_real_wait_async_co (self);
678 	return result;
679 }
680 
681 static void
_vala_array_add1(GeeFutureSourceFuncArrayElement ** array,int * length,int * size,const GeeFutureSourceFuncArrayElement * value)682 _vala_array_add1 (GeeFutureSourceFuncArrayElement* * array,
683                   int* length,
684                   int* size,
685                   const GeeFutureSourceFuncArrayElement* value)
686 {
687 	if ((*length) == (*size)) {
688 		*size = (*size) ? (2 * (*size)) : 4;
689 		*array = g_renew (GeeFutureSourceFuncArrayElement, *array, *size);
690 	}
691 	(*array)[(*length)++] = *value;
692 }
693 
694 static void
gee_lazy_future_wait_async_ready(GObject * source_object,GAsyncResult * _res_,gpointer _user_data_)695 gee_lazy_future_wait_async_ready (GObject* source_object,
696                                   GAsyncResult* _res_,
697                                   gpointer _user_data_)
698 {
699 	GeeLazyFutureWaitAsyncData* _data_;
700 	_data_ = _user_data_;
701 	_data_->_source_object_ = source_object;
702 	_data_->_res_ = _res_;
703 	gee_lazy_future_real_wait_async_co (_data_);
704 }
705 
706 static gboolean
gee_lazy_future_real_wait_async_co(GeeLazyFutureWaitAsyncData * _data_)707 gee_lazy_future_real_wait_async_co (GeeLazyFutureWaitAsyncData* _data_)
708 {
709 	switch (_data_->_state_) {
710 		case 0:
711 		goto _state_0;
712 		case 1:
713 		goto _state_1;
714 		default:
715 		g_assert_not_reached ();
716 	}
717 	_state_0:
718 	g_mutex_lock (&_data_->self->priv->_mutex);
719 	_data_->_tmp0_ = _data_->self->priv->_lazy;
720 	_data_->_tmp1_ = _data_->_tmp0_->priv->_func;
721 	_data_->_tmp1__target = _data_->_tmp0_->priv->_func_target;
722 	if (_data_->_tmp1_ != NULL) {
723 		_data_->_tmp2_ = _data_->self->priv->_state;
724 		if (_data_->_tmp2_ == GEE_LAZY_FUTURE_STATE_EVAL) {
725 			_data_->_tmp3_ = _data_->self->priv->_when_done;
726 			_data_->_tmp3__length1 = _data_->self->priv->_when_done_length1;
727 			memset (&_data_->_tmp4_, 0, sizeof (GeeFutureSourceFuncArrayElement));
728 			gee_future_source_func_array_element_init (&_data_->_tmp4_, _gee_lazy_future_real_wait_async_co_gsource_func, _data_, NULL);
729 			_vala_array_add1 (&_data_->self->priv->_when_done, &_data_->self->priv->_when_done_length1, &_data_->self->priv->__when_done_size_, &_data_->_tmp4_);
730 			_data_->_state_ = 1;
731 			gee_utils_async_yield_and_unlock (&_data_->self->priv->_mutex, gee_lazy_future_wait_async_ready, _data_);
732 			return FALSE;
733 			_state_1:
734 			gee_utils_async_yield_and_unlock_finish (_data_->_res_);
735 		} else {
736 			gee_lazy_future_do_eval (_data_->self);
737 		}
738 	} else {
739 		g_mutex_unlock (&_data_->self->priv->_mutex);
740 	}
741 	_data_->_tmp5_ = _data_->self->priv->_lazy;
742 	_data_->_tmp6_ = gee_lazy_get_value (_data_->_tmp5_);
743 	_data_->_tmp7_ = _data_->_tmp6_;
744 	_data_->result = _data_->_tmp7_;
745 	g_task_return_pointer (_data_->_async_result, _data_, NULL);
746 	if (_data_->_state_ != 0) {
747 		while (!g_task_get_completed (_data_->_async_result)) {
748 			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
749 		}
750 	}
751 	g_object_unref (_data_->_async_result);
752 	return FALSE;
753 }
754 
755 static void
gee_lazy_future_do_eval(GeeLazyFuture * self)756 gee_lazy_future_do_eval (GeeLazyFuture* self)
757 {
758 	GeeLazy* _tmp0_;
759 	GeeLazy* _tmp1_;
760 	GeeLazyFunc _tmp2_;
761 	gpointer _tmp2__target;
762 	gpointer _tmp3_;
763 	GeeLazy* _tmp4_;
764 	GeeFutureSourceFuncArrayElement* when_done = NULL;
765 	GeeFutureSourceFuncArrayElement* _tmp5_;
766 	gint _tmp5__length1;
767 	gint when_done_length1;
768 	gint _when_done_size_;
769 	g_return_if_fail (self != NULL);
770 	self->priv->_state = GEE_LAZY_FUTURE_STATE_EVAL;
771 	g_mutex_unlock (&self->priv->_mutex);
772 	_tmp0_ = self->priv->_lazy;
773 	_tmp1_ = self->priv->_lazy;
774 	_tmp2_ = _tmp1_->priv->_func;
775 	_tmp2__target = _tmp1_->priv->_func_target;
776 	_tmp3_ = _tmp2_ (_tmp2__target);
777 	((_tmp0_->priv->_value == NULL) || (self->priv->g_destroy_func == NULL)) ? NULL : (_tmp0_->priv->_value = (self->priv->g_destroy_func (_tmp0_->priv->_value), NULL));
778 	_tmp0_->priv->_value = _tmp3_;
779 	g_mutex_lock (&self->priv->_mutex);
780 	_tmp4_ = self->priv->_lazy;
781 	(_tmp4_->priv->_func_target_destroy_notify == NULL) ? NULL : (_tmp4_->priv->_func_target_destroy_notify (_tmp4_->priv->_func_target), NULL);
782 	_tmp4_->priv->_func = NULL;
783 	_tmp4_->priv->_func_target = NULL;
784 	_tmp4_->priv->_func_target_destroy_notify = NULL;
785 	_tmp4_->priv->_func = NULL;
786 	_tmp4_->priv->_func_target = NULL;
787 	_tmp4_->priv->_func_target_destroy_notify = NULL;
788 	self->priv->_state = GEE_LAZY_FUTURE_STATE_UNLOCK;
789 	g_cond_broadcast (&self->priv->_eval);
790 	g_mutex_unlock (&self->priv->_mutex);
791 	_tmp5_ = self->priv->_when_done;
792 	_tmp5__length1 = self->priv->_when_done_length1;
793 	self->priv->_when_done = NULL;
794 	self->priv->_when_done_length1 = 0;
795 	when_done = _tmp5_;
796 	when_done_length1 = _tmp5__length1;
797 	_when_done_size_ = when_done_length1;
798 	{
799 		gint i = 0;
800 		i = 0;
801 		{
802 			gboolean _tmp6_ = FALSE;
803 			_tmp6_ = TRUE;
804 			while (TRUE) {
805 				GeeFutureSourceFuncArrayElement* _tmp8_;
806 				gint _tmp8__length1;
807 				GeeFutureSourceFuncArrayElement* _tmp9_;
808 				gint _tmp9__length1;
809 				GeeFutureSourceFuncArrayElement _tmp10_;
810 				GSourceFunc _tmp11_;
811 				gpointer _tmp11__target;
812 				if (!_tmp6_) {
813 					gint _tmp7_;
814 					_tmp7_ = i;
815 					i = _tmp7_ + 1;
816 				}
817 				_tmp6_ = FALSE;
818 				_tmp8_ = when_done;
819 				_tmp8__length1 = when_done_length1;
820 				if (!(i < _tmp8__length1)) {
821 					break;
822 				}
823 				_tmp9_ = when_done;
824 				_tmp9__length1 = when_done_length1;
825 				_tmp10_ = _tmp9_[i];
826 				_tmp11_ = _tmp10_.func;
827 				_tmp11__target = _tmp10_.func_target;
828 				_tmp11_ (_tmp11__target);
829 			}
830 		}
831 	}
832 	when_done = (_vala_GeeFutureSourceFuncArrayElement_array_free (when_done, when_done_length1), NULL);
833 }
834 
835 static gboolean
gee_lazy_future_real_get_ready(GeeFuture * base)836 gee_lazy_future_real_get_ready (GeeFuture* base)
837 {
838 	gboolean result;
839 	GeeLazyFuture* self;
840 	gboolean _result_ = FALSE;
841 	GeeLazy* _tmp0_;
842 	GeeLazyFunc _tmp1_;
843 	gpointer _tmp1__target;
844 	self = (GeeLazyFuture*) base;
845 	g_mutex_lock (&self->priv->_mutex);
846 	_tmp0_ = self->priv->_lazy;
847 	_tmp1_ = _tmp0_->priv->_func;
848 	_tmp1__target = _tmp0_->priv->_func_target;
849 	_result_ = _tmp1_ == NULL;
850 	g_mutex_unlock (&self->priv->_mutex);
851 	result = _result_;
852 	return result;
853 }
854 
855 static GError*
gee_lazy_future_real_get_exception(GeeFuture * base)856 gee_lazy_future_real_get_exception (GeeFuture* base)
857 {
858 	GError* result;
859 	GeeLazyFuture* self;
860 	self = (GeeLazyFuture*) base;
861 	result = NULL;
862 	return result;
863 }
864 
865 static void
gee_lazy_future_class_init(GeeLazyFutureClass * klass,gpointer klass_data)866 gee_lazy_future_class_init (GeeLazyFutureClass * klass,
867                             gpointer klass_data)
868 {
869 	gee_lazy_future_parent_class = g_type_class_peek_parent (klass);
870 	g_type_class_adjust_private_offset (klass, &GeeLazyFuture_private_offset);
871 	G_OBJECT_CLASS (klass)->get_property = _vala_gee_lazy_future_get_property;
872 	G_OBJECT_CLASS (klass)->set_property = _vala_gee_lazy_future_set_property;
873 	G_OBJECT_CLASS (klass)->finalize = gee_lazy_future_finalize;
874 	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_LAZY_FUTURE_G_TYPE, g_param_spec_gtype ("g-type", "type", "type", G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
875 	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_LAZY_FUTURE_G_DUP_FUNC, g_param_spec_pointer ("g-dup-func", "dup func", "dup func", G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
876 	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_LAZY_FUTURE_G_DESTROY_FUNC, g_param_spec_pointer ("g-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
877 	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_LAZY_FUTURE_READY_PROPERTY, gee_lazy_future_properties[GEE_LAZY_FUTURE_READY_PROPERTY] = g_param_spec_boolean ("ready", "ready", "ready", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
878 	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_LAZY_FUTURE_EXCEPTION_PROPERTY, gee_lazy_future_properties[GEE_LAZY_FUTURE_EXCEPTION_PROPERTY] = g_param_spec_pointer ("exception", "exception", "exception", G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
879 }
880 
881 static GType
gee_lazy_future_gee_future_get_g_type(GeeLazyFuture * self)882 gee_lazy_future_gee_future_get_g_type (GeeLazyFuture* self)
883 {
884 	return self->priv->g_type;
885 }
886 
887 static GBoxedCopyFunc
gee_lazy_future_gee_future_get_g_dup_func(GeeLazyFuture * self)888 gee_lazy_future_gee_future_get_g_dup_func (GeeLazyFuture* self)
889 {
890 	return self->priv->g_dup_func;
891 }
892 
893 static GDestroyNotify
gee_lazy_future_gee_future_get_g_destroy_func(GeeLazyFuture * self)894 gee_lazy_future_gee_future_get_g_destroy_func (GeeLazyFuture* self)
895 {
896 	return self->priv->g_destroy_func;
897 }
898 
899 static void
gee_lazy_future_gee_future_interface_init(GeeFutureIface * iface,gpointer iface_data)900 gee_lazy_future_gee_future_interface_init (GeeFutureIface * iface,
901                                            gpointer iface_data)
902 {
903 	gee_lazy_future_gee_future_parent_iface = g_type_interface_peek_parent (iface);
904 	iface->wait = (gconstpointer (*) (GeeFuture*, GError**)) gee_lazy_future_real_wait;
905 	iface->wait_until = (gboolean (*) (GeeFuture*, gint64, gconstpointer*, GError**)) gee_lazy_future_real_wait_until;
906 	iface->wait_async = (void (*) (GeeFuture*, GAsyncReadyCallback, gpointer)) gee_lazy_future_real_wait_async;
907 	iface->wait_finish = (gconstpointer (*) (GeeFuture*, GAsyncResult*, GError**)) gee_lazy_future_wait_finish;
908 	iface->get_g_type = (GType (*) (GeeFuture *)) gee_lazy_future_gee_future_get_g_type;
909 	iface->get_g_dup_func = (GBoxedCopyFunc (*) (GeeFuture *)) gee_lazy_future_gee_future_get_g_dup_func;
910 	iface->get_g_destroy_func = (GDestroyNotify (*) (GeeFuture *)) gee_lazy_future_gee_future_get_g_destroy_func;
911 	iface->get_ready = gee_lazy_future_real_get_ready;
912 	iface->get_exception = gee_lazy_future_real_get_exception;
913 }
914 
915 static void
gee_lazy_future_instance_init(GeeLazyFuture * self,gpointer klass)916 gee_lazy_future_instance_init (GeeLazyFuture * self,
917                                gpointer klass)
918 {
919 	self->priv = gee_lazy_future_get_instance_private (self);
920 	g_mutex_init (&self->priv->_mutex);
921 	g_cond_init (&self->priv->_eval);
922 	self->priv->_state = GEE_LAZY_FUTURE_STATE_UNLOCK;
923 }
924 
925 static void
gee_lazy_future_finalize(GObject * obj)926 gee_lazy_future_finalize (GObject * obj)
927 {
928 	GeeLazyFuture * self;
929 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEE_LAZY_TYPE_FUTURE, GeeLazyFuture);
930 	_vala_clear_GMutex (&self->priv->_mutex);
931 	_vala_clear_GCond (&self->priv->_eval);
932 	_gee_lazy_unref0 (self->priv->_lazy);
933 	self->priv->_when_done = (_vala_GeeFutureSourceFuncArrayElement_array_free (self->priv->_when_done, self->priv->_when_done_length1), NULL);
934 	G_OBJECT_CLASS (gee_lazy_future_parent_class)->finalize (obj);
935 }
936 
937 static GType
gee_lazy_future_get_type(void)938 gee_lazy_future_get_type (void)
939 {
940 	static volatile gsize gee_lazy_future_type_id__volatile = 0;
941 	if (g_once_init_enter (&gee_lazy_future_type_id__volatile)) {
942 		static const GTypeInfo g_define_type_info = { sizeof (GeeLazyFutureClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gee_lazy_future_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GeeLazyFuture), 0, (GInstanceInitFunc) gee_lazy_future_instance_init, NULL };
943 		static const GInterfaceInfo gee_future_info = { (GInterfaceInitFunc) gee_lazy_future_gee_future_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
944 		GType gee_lazy_future_type_id;
945 		gee_lazy_future_type_id = g_type_register_static (G_TYPE_OBJECT, "GeeLazyFuture", &g_define_type_info, 0);
946 		g_type_add_interface_static (gee_lazy_future_type_id, GEE_TYPE_FUTURE, &gee_future_info);
947 		GeeLazyFuture_private_offset = g_type_add_instance_private (gee_lazy_future_type_id, sizeof (GeeLazyFuturePrivate));
948 		g_once_init_leave (&gee_lazy_future_type_id__volatile, gee_lazy_future_type_id);
949 	}
950 	return gee_lazy_future_type_id__volatile;
951 }
952 
953 static void
_vala_gee_lazy_future_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)954 _vala_gee_lazy_future_get_property (GObject * object,
955                                     guint property_id,
956                                     GValue * value,
957                                     GParamSpec * pspec)
958 {
959 	GeeLazyFuture * self;
960 	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEE_LAZY_TYPE_FUTURE, GeeLazyFuture);
961 	switch (property_id) {
962 		case GEE_LAZY_FUTURE_READY_PROPERTY:
963 		g_value_set_boolean (value, gee_future_get_ready ((GeeFuture*) self));
964 		break;
965 		case GEE_LAZY_FUTURE_EXCEPTION_PROPERTY:
966 		g_value_set_pointer (value, gee_future_get_exception ((GeeFuture*) self));
967 		break;
968 		case GEE_LAZY_FUTURE_G_TYPE:
969 		g_value_set_gtype (value, self->priv->g_type);
970 		break;
971 		case GEE_LAZY_FUTURE_G_DUP_FUNC:
972 		g_value_set_pointer (value, self->priv->g_dup_func);
973 		break;
974 		case GEE_LAZY_FUTURE_G_DESTROY_FUNC:
975 		g_value_set_pointer (value, self->priv->g_destroy_func);
976 		break;
977 		default:
978 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
979 		break;
980 	}
981 }
982 
983 static void
_vala_gee_lazy_future_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)984 _vala_gee_lazy_future_set_property (GObject * object,
985                                     guint property_id,
986                                     const GValue * value,
987                                     GParamSpec * pspec)
988 {
989 	GeeLazyFuture * self;
990 	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEE_LAZY_TYPE_FUTURE, GeeLazyFuture);
991 	switch (property_id) {
992 		case GEE_LAZY_FUTURE_G_TYPE:
993 		self->priv->g_type = g_value_get_gtype (value);
994 		break;
995 		case GEE_LAZY_FUTURE_G_DUP_FUNC:
996 		self->priv->g_dup_func = g_value_get_pointer (value);
997 		break;
998 		case GEE_LAZY_FUTURE_G_DESTROY_FUNC:
999 		self->priv->g_destroy_func = g_value_get_pointer (value);
1000 		break;
1001 		default:
1002 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1003 		break;
1004 	}
1005 }
1006 
1007 static void
gee_value_lazy_init(GValue * value)1008 gee_value_lazy_init (GValue* value)
1009 {
1010 	value->data[0].v_pointer = NULL;
1011 }
1012 
1013 static void
gee_value_lazy_free_value(GValue * value)1014 gee_value_lazy_free_value (GValue* value)
1015 {
1016 	if (value->data[0].v_pointer) {
1017 		gee_lazy_unref (value->data[0].v_pointer);
1018 	}
1019 }
1020 
1021 static void
gee_value_lazy_copy_value(const GValue * src_value,GValue * dest_value)1022 gee_value_lazy_copy_value (const GValue* src_value,
1023                            GValue* dest_value)
1024 {
1025 	if (src_value->data[0].v_pointer) {
1026 		dest_value->data[0].v_pointer = gee_lazy_ref (src_value->data[0].v_pointer);
1027 	} else {
1028 		dest_value->data[0].v_pointer = NULL;
1029 	}
1030 }
1031 
1032 static gpointer
gee_value_lazy_peek_pointer(const GValue * value)1033 gee_value_lazy_peek_pointer (const GValue* value)
1034 {
1035 	return value->data[0].v_pointer;
1036 }
1037 
1038 static gchar*
gee_value_lazy_collect_value(GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)1039 gee_value_lazy_collect_value (GValue* value,
1040                               guint n_collect_values,
1041                               GTypeCValue* collect_values,
1042                               guint collect_flags)
1043 {
1044 	if (collect_values[0].v_pointer) {
1045 		GeeLazy * object;
1046 		object = collect_values[0].v_pointer;
1047 		if (object->parent_instance.g_class == NULL) {
1048 			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
1049 		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
1050 			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
1051 		}
1052 		value->data[0].v_pointer = gee_lazy_ref (object);
1053 	} else {
1054 		value->data[0].v_pointer = NULL;
1055 	}
1056 	return NULL;
1057 }
1058 
1059 static gchar*
gee_value_lazy_lcopy_value(const GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)1060 gee_value_lazy_lcopy_value (const GValue* value,
1061                             guint n_collect_values,
1062                             GTypeCValue* collect_values,
1063                             guint collect_flags)
1064 {
1065 	GeeLazy ** object_p;
1066 	object_p = collect_values[0].v_pointer;
1067 	if (!object_p) {
1068 		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
1069 	}
1070 	if (!value->data[0].v_pointer) {
1071 		*object_p = NULL;
1072 	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
1073 		*object_p = value->data[0].v_pointer;
1074 	} else {
1075 		*object_p = gee_lazy_ref (value->data[0].v_pointer);
1076 	}
1077 	return NULL;
1078 }
1079 
1080 GParamSpec*
gee_param_spec_lazy(const gchar * name,const gchar * nick,const gchar * blurb,GType object_type,GParamFlags flags)1081 gee_param_spec_lazy (const gchar* name,
1082                      const gchar* nick,
1083                      const gchar* blurb,
1084                      GType object_type,
1085                      GParamFlags flags)
1086 {
1087 	GeeParamSpecLazy* spec;
1088 	g_return_val_if_fail (g_type_is_a (object_type, GEE_TYPE_LAZY), NULL);
1089 	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
1090 	G_PARAM_SPEC (spec)->value_type = object_type;
1091 	return G_PARAM_SPEC (spec);
1092 }
1093 
1094 gpointer
gee_value_get_lazy(const GValue * value)1095 gee_value_get_lazy (const GValue* value)
1096 {
1097 	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEE_TYPE_LAZY), NULL);
1098 	return value->data[0].v_pointer;
1099 }
1100 
1101 void
gee_value_set_lazy(GValue * value,gpointer v_object)1102 gee_value_set_lazy (GValue* value,
1103                     gpointer v_object)
1104 {
1105 	GeeLazy * old;
1106 	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEE_TYPE_LAZY));
1107 	old = value->data[0].v_pointer;
1108 	if (v_object) {
1109 		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GEE_TYPE_LAZY));
1110 		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
1111 		value->data[0].v_pointer = v_object;
1112 		gee_lazy_ref (value->data[0].v_pointer);
1113 	} else {
1114 		value->data[0].v_pointer = NULL;
1115 	}
1116 	if (old) {
1117 		gee_lazy_unref (old);
1118 	}
1119 }
1120 
1121 void
gee_value_take_lazy(GValue * value,gpointer v_object)1122 gee_value_take_lazy (GValue* value,
1123                      gpointer v_object)
1124 {
1125 	GeeLazy * old;
1126 	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEE_TYPE_LAZY));
1127 	old = value->data[0].v_pointer;
1128 	if (v_object) {
1129 		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GEE_TYPE_LAZY));
1130 		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
1131 		value->data[0].v_pointer = v_object;
1132 	} else {
1133 		value->data[0].v_pointer = NULL;
1134 	}
1135 	if (old) {
1136 		gee_lazy_unref (old);
1137 	}
1138 }
1139 
1140 static void
gee_lazy_class_init(GeeLazyClass * klass,gpointer klass_data)1141 gee_lazy_class_init (GeeLazyClass * klass,
1142                      gpointer klass_data)
1143 {
1144 	gee_lazy_parent_class = g_type_class_peek_parent (klass);
1145 	((GeeLazyClass *) klass)->finalize = gee_lazy_finalize;
1146 	g_type_class_adjust_private_offset (klass, &GeeLazy_private_offset);
1147 }
1148 
1149 static void
gee_lazy_instance_init(GeeLazy * self,gpointer klass)1150 gee_lazy_instance_init (GeeLazy * self,
1151                         gpointer klass)
1152 {
1153 	self->priv = gee_lazy_get_instance_private (self);
1154 	self->ref_count = 1;
1155 }
1156 
1157 static void
gee_lazy_finalize(GeeLazy * obj)1158 gee_lazy_finalize (GeeLazy * obj)
1159 {
1160 	GeeLazy * self;
1161 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEE_TYPE_LAZY, GeeLazy);
1162 	g_signal_handlers_destroy (self);
1163 	(self->priv->_func_target_destroy_notify == NULL) ? NULL : (self->priv->_func_target_destroy_notify (self->priv->_func_target), NULL);
1164 	self->priv->_func = NULL;
1165 	self->priv->_func_target = NULL;
1166 	self->priv->_func_target_destroy_notify = NULL;
1167 	((self->priv->_value == NULL) || (self->priv->g_destroy_func == NULL)) ? NULL : (self->priv->_value = (self->priv->g_destroy_func (self->priv->_value), NULL));
1168 }
1169 
1170 /**
1171  * Represents a lazy value. I.e. value that is computed on demand.
1172  *
1173  * This class is not thread-safe.
1174  */
1175 GType
gee_lazy_get_type(void)1176 gee_lazy_get_type (void)
1177 {
1178 	static volatile gsize gee_lazy_type_id__volatile = 0;
1179 	if (g_once_init_enter (&gee_lazy_type_id__volatile)) {
1180 		static const GTypeValueTable g_define_type_value_table = { gee_value_lazy_init, gee_value_lazy_free_value, gee_value_lazy_copy_value, gee_value_lazy_peek_pointer, "p", gee_value_lazy_collect_value, "p", gee_value_lazy_lcopy_value };
1181 		static const GTypeInfo g_define_type_info = { sizeof (GeeLazyClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gee_lazy_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GeeLazy), 0, (GInstanceInitFunc) gee_lazy_instance_init, &g_define_type_value_table };
1182 		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
1183 		GType gee_lazy_type_id;
1184 		gee_lazy_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GeeLazy", &g_define_type_info, &g_define_type_fundamental_info, 0);
1185 		GeeLazy_private_offset = g_type_add_instance_private (gee_lazy_type_id, sizeof (GeeLazyPrivate));
1186 		g_once_init_leave (&gee_lazy_type_id__volatile, gee_lazy_type_id);
1187 	}
1188 	return gee_lazy_type_id__volatile;
1189 }
1190 
1191 gpointer
gee_lazy_ref(gpointer instance)1192 gee_lazy_ref (gpointer instance)
1193 {
1194 	GeeLazy * self;
1195 	self = instance;
1196 	g_atomic_int_inc (&self->ref_count);
1197 	return instance;
1198 }
1199 
1200 void
gee_lazy_unref(gpointer instance)1201 gee_lazy_unref (gpointer instance)
1202 {
1203 	GeeLazy * self;
1204 	self = instance;
1205 	if (g_atomic_int_dec_and_test (&self->ref_count)) {
1206 		GEE_LAZY_GET_CLASS (self)->finalize (self);
1207 		g_type_free_instance ((GTypeInstance *) self);
1208 	}
1209 }
1210 
1211 static void
_vala_clear_GMutex(GMutex * mutex)1212 _vala_clear_GMutex (GMutex * mutex)
1213 {
1214 	GMutex zero_mutex = { 0 };
1215 	if (memcmp (mutex, &zero_mutex, sizeof (GMutex))) {
1216 		g_mutex_clear (mutex);
1217 		memset (mutex, 0, sizeof (GMutex));
1218 	}
1219 }
1220 
1221 static void
_vala_clear_GRecMutex(GRecMutex * mutex)1222 _vala_clear_GRecMutex (GRecMutex * mutex)
1223 {
1224 	GRecMutex zero_mutex = { 0 };
1225 	if (memcmp (mutex, &zero_mutex, sizeof (GRecMutex))) {
1226 		g_rec_mutex_clear (mutex);
1227 		memset (mutex, 0, sizeof (GRecMutex));
1228 	}
1229 }
1230 
1231 static void
_vala_clear_GRWLock(GRWLock * mutex)1232 _vala_clear_GRWLock (GRWLock * mutex)
1233 {
1234 	GRWLock zero_mutex = { 0 };
1235 	if (memcmp (mutex, &zero_mutex, sizeof (GRWLock))) {
1236 		g_rw_lock_clear (mutex);
1237 		memset (mutex, 0, sizeof (GRWLock));
1238 	}
1239 }
1240 
1241 static void
_vala_clear_GCond(GCond * mutex)1242 _vala_clear_GCond (GCond * mutex)
1243 {
1244 	GCond zero_mutex = { 0 };
1245 	if (memcmp (mutex, &zero_mutex, sizeof (GCond))) {
1246 		g_cond_clear (mutex);
1247 		memset (mutex, 0, sizeof (GCond));
1248 	}
1249 }
1250 
1251