/* mapfuture.c generated by valac 0.20.1.52-2186, the Vala compiler
 * generated from mapfuture.vala, do not modify */

/* mapfuture.vala
 *
 * Copyright (C) 2013  Maciej Piechotka
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Maciej Piechotka <uzytkownik2@gmail.com>
 */

#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <string.h>


#define GEE_TYPE_FUTURE (gee_future_get_type ())
#define GEE_FUTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_FUTURE, GeeFuture))
#define GEE_IS_FUTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_FUTURE))
#define GEE_FUTURE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_FUTURE, GeeFutureIface))

typedef struct _GeeFuture GeeFuture;
typedef struct _GeeFutureIface GeeFutureIface;

#define GEE_TYPE_MAP_FUTURE (gee_map_future_get_type ())
#define GEE_MAP_FUTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_MAP_FUTURE, GeeMapFuture))
#define GEE_MAP_FUTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_MAP_FUTURE, GeeMapFutureClass))
#define GEE_IS_MAP_FUTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_MAP_FUTURE))
#define GEE_IS_MAP_FUTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_MAP_FUTURE))
#define GEE_MAP_FUTURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_MAP_FUTURE, GeeMapFutureClass))

typedef struct _GeeMapFuture GeeMapFuture;
typedef struct _GeeMapFutureClass GeeMapFutureClass;
typedef struct _GeeMapFuturePrivate GeeMapFuturePrivate;

#define GEE_MAP_FUTURE_TYPE_PROGRESS (gee_map_future_progress_get_type ())

#define GEE_FUTURE_TYPE_WHEN_DONE_ARRAY_ELEMENT (gee_future_when_done_array_element_get_type ())
typedef struct _GeeFutureWhenDoneArrayElement GeeFutureWhenDoneArrayElement;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block9Data Block9Data;
typedef struct _GeeMapFutureWaitAsyncData GeeMapFutureWaitAsyncData;

typedef void (*GeeFutureWhenDoneFunc) (gconstpointer value, void* user_data);
typedef gpointer (*GeeFutureMapFunc) (gconstpointer value, void* user_data);
typedef gconstpointer (*GeeFutureLightMapFunc) (gconstpointer value, void* user_data);
typedef gpointer (*GeeFutureZipFunc) (gconstpointer a, gconstpointer b, void* user_data);
typedef GeeFuture* (*GeeFutureFlatMapFunc) (gconstpointer value, void* user_data);
struct _GeeFutureIface {
	GTypeInterface parent_iface;
	GType (*get_g_type) (GeeFuture* self);
	GBoxedCopyFunc (*get_g_dup_func) (GeeFuture* self);
	GDestroyNotify (*get_g_destroy_func) (GeeFuture* self);
	gconstpointer (*wait) (GeeFuture* self);
	gboolean (*wait_until) (GeeFuture* self, gint64 end_time, gconstpointer* value);
	void (*wait_async) (GeeFuture* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
	gconstpointer (*wait_finish) (GeeFuture* self, GAsyncResult* _res_);
	void (*when_done) (GeeFuture* self, GeeFutureWhenDoneFunc func, void* func_target);
	GeeFuture* (*map) (GeeFuture* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFutureMapFunc func, void* func_target);
	GeeFuture* (*light_map) (GeeFuture* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFutureLightMapFunc func, void* func_target);
	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, void* zip_func_target, GeeFuture* second);
	GeeFuture* (*flat_map) (GeeFuture* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFutureFlatMapFunc func, void* func_target);
	gconstpointer (*get_value) (GeeFuture* self);
	gboolean (*get_ready) (GeeFuture* self);
};

struct _GeeMapFuture {
	GObject parent_instance;
	GeeMapFuturePrivate * priv;
};

struct _GeeMapFutureClass {
	GObjectClass parent_class;
};

typedef enum  {
	GEE_MAP_FUTURE_PROGRESS_INIT,
	GEE_MAP_FUTURE_PROGRESS_PROGRESS,
	GEE_MAP_FUTURE_PROGRESS_READY
} GeeMapFutureProgress;

struct _GeeFutureWhenDoneArrayElement {
	GeeFutureWhenDoneFunc func;
	gpointer func_target;
	GDestroyNotify func_target_destroy_notify;
};

struct _GeeMapFuturePrivate {
	GType a_type;
	GBoxedCopyFunc a_dup_func;
	GDestroyNotify a_destroy_func;
	GType g_type;
	GBoxedCopyFunc g_dup_func;
	GDestroyNotify g_destroy_func;
	GMutex _mutex;
	GCond _cond;
	GeeFuture* _base;
	GeeFutureMapFunc _func;
	gpointer _func_target;
	GDestroyNotify _func_target_destroy_notify;
	gpointer _value;
	GeeMapFutureProgress _progress;
	GeeFutureWhenDoneArrayElement* _when_done;
	gint _when_done_length1;
	gint __when_done_size_;
};

struct _Block9Data {
	int _ref_count_;
	GeeMapFuture * self;
	gpointer _async_data_;
};

struct _GeeMapFutureWaitAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	GeeMapFuture* self;
	gconstpointer result;
	Block9Data* _data9_;
	GeeMapFutureProgress progress;
	GeeMapFutureProgress _tmp0_;
	GeeMapFutureProgress _tmp1_;
	GeeFuture* base_future;
	GeeFuture* _tmp2_;
	GeeFuture* _tmp3_;
	GeeFuture* _tmp4_;
	GeeMapFutureProgress _tmp5_;
	gconstpointer _result_;
	GeeFutureWhenDoneArrayElement* _tmp6_;
	gint _tmp6__length1;
	GeeFutureWhenDoneArrayElement _tmp7_;
	gconstpointer _tmp8_;
	GeeMapFutureProgress _tmp9_;
	gconstpointer _tmp10_;
};


static gpointer gee_map_future_parent_class = NULL;
static GeeFutureIface* gee_map_future_gee_future_parent_iface = NULL;

GType gee_future_get_type (void) G_GNUC_CONST;
GType gee_map_future_get_type (void) G_GNUC_CONST;
static GType gee_map_future_progress_get_type (void) G_GNUC_UNUSED;
GType gee_future_when_done_array_element_get_type (void) G_GNUC_CONST;
GeeFutureWhenDoneArrayElement* gee_future_when_done_array_element_dup (const GeeFutureWhenDoneArrayElement* self);
void gee_future_when_done_array_element_free (GeeFutureWhenDoneArrayElement* self);
void gee_future_when_done_array_element_copy (const GeeFutureWhenDoneArrayElement* self, GeeFutureWhenDoneArrayElement* dest);
void gee_future_when_done_array_element_destroy (GeeFutureWhenDoneArrayElement* self);
#define GEE_MAP_FUTURE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GEE_TYPE_MAP_FUTURE, GeeMapFuturePrivate))
enum  {
	GEE_MAP_FUTURE_DUMMY_PROPERTY,
	GEE_MAP_FUTURE_A_TYPE,
	GEE_MAP_FUTURE_A_DUP_FUNC,
	GEE_MAP_FUTURE_A_DESTROY_FUNC,
	GEE_MAP_FUTURE_G_TYPE,
	GEE_MAP_FUTURE_G_DUP_FUNC,
	GEE_MAP_FUTURE_G_DESTROY_FUNC,
	GEE_MAP_FUTURE_READY
};
static void _vala_GeeFutureWhenDoneArrayElement_array_free (GeeFutureWhenDoneArrayElement* array, gint array_length);
GeeMapFuture* gee_map_future_new (GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeFuture* future_base, GeeFutureMapFunc func, void* func_target);
GeeMapFuture* gee_map_future_construct (GType object_type, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeFuture* future_base, GeeFutureMapFunc func, void* func_target);
void gee_future_when_done (GeeFuture* self, GeeFutureWhenDoneFunc func, void* func_target);
static void __lambda40_ (GeeMapFuture* self, gconstpointer val);
static inline gconstpointer gee_map_future_go_map (GeeMapFuture* self, gconstpointer val);
static void ___lambda40__gee_future_when_done_func (gconstpointer value, gpointer self);
static gconstpointer gee_map_future_real_wait (GeeFuture* base);
gconstpointer gee_future_wait (GeeFuture* self);
static gboolean gee_map_future_real_wait_until (GeeFuture* base, gint64 end_time, gconstpointer* value);
gboolean gee_future_wait_until (GeeFuture* self, gint64 end_time, gconstpointer* value);
static void gee_map_future_real_wait_async_data_free (gpointer _data);
static void gee_map_future_real_wait_async (GeeFuture* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean gee_map_future_real_wait_async_co (GeeMapFutureWaitAsyncData* _data_);
static Block9Data* block9_data_ref (Block9Data* _data9_);
static void block9_data_unref (void * _userdata_);
void gee_future_wait_async (GeeFuture* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
gconstpointer gee_future_wait_finish (GeeFuture* self, GAsyncResult* _res_);
static void gee_map_future_wait_async_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void ___lambda41_ (Block9Data* _data9_, gconstpointer res);
static void ____lambda41__gee_future_when_done_func (gconstpointer value, gpointer self);
void gee_future_when_done_array_element_init (GeeFutureWhenDoneArrayElement *self, GeeFutureWhenDoneFunc func, void* func_target);
static void _vala_array_add3 (GeeFutureWhenDoneArrayElement** array, int* length, int* size, const GeeFutureWhenDoneArrayElement* value);
static void gee_map_future_real_when_done (GeeFuture* base, GeeFutureWhenDoneFunc func, void* func_target);
static void _vala_array_add4 (GeeFutureWhenDoneArrayElement** array, int* length, int* size, const GeeFutureWhenDoneArrayElement* value);
static void gee_map_future_finalize (GObject* obj);
gboolean gee_future_get_ready (GeeFuture* self);
static void _vala_gee_map_future_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_gee_map_future_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
static void _vala_clear_GMutex (GMutex * mutex);
static void _vala_clear_GRecMutex (GRecMutex * mutex);
static void _vala_clear_GRWLock (GRWLock * mutex);
static void _vala_clear_GCond (GCond * mutex);


static GType gee_map_future_progress_get_type (void) {
	static volatile gsize gee_map_future_progress_type_id__volatile = 0;
	if (g_once_init_enter (&gee_map_future_progress_type_id__volatile)) {
		static const GEnumValue values[] = {{GEE_MAP_FUTURE_PROGRESS_INIT, "GEE_MAP_FUTURE_PROGRESS_INIT", "init"}, {GEE_MAP_FUTURE_PROGRESS_PROGRESS, "GEE_MAP_FUTURE_PROGRESS_PROGRESS", "progress"}, {GEE_MAP_FUTURE_PROGRESS_READY, "GEE_MAP_FUTURE_PROGRESS_READY", "ready"}, {0, NULL, NULL}};
		GType gee_map_future_progress_type_id;
		gee_map_future_progress_type_id = g_enum_register_static ("GeeMapFutureProgress", values);
		g_once_init_leave (&gee_map_future_progress_type_id__volatile, gee_map_future_progress_type_id);
	}
	return gee_map_future_progress_type_id__volatile;
}


static void _vala_GeeFutureWhenDoneArrayElement_array_free (GeeFutureWhenDoneArrayElement* array, gint array_length) {
	if (array != NULL) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			gee_future_when_done_array_element_destroy (&array[i]);
		}
	}
	g_free (array);
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static void __lambda40_ (GeeMapFuture* self, gconstpointer val) {
	GeeMapFutureProgress _tmp0_ = 0;
	g_mutex_lock (&self->priv->_mutex);
	_tmp0_ = self->priv->_progress;
	if (_tmp0_ == GEE_MAP_FUTURE_PROGRESS_INIT) {
		gconstpointer _tmp1_ = NULL;
		_tmp1_ = val;
		gee_map_future_go_map (self, _tmp1_);
	} else {
		g_mutex_unlock (&self->priv->_mutex);
	}
}


static void ___lambda40__gee_future_when_done_func (gconstpointer value, gpointer self) {
	__lambda40_ (self, value);
	g_object_unref (self);
}


GeeMapFuture* gee_map_future_construct (GType object_type, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeFuture* future_base, GeeFutureMapFunc func, void* func_target) {
	GeeMapFuture * self = NULL;
	GeeFuture* _tmp0_ = NULL;
	GeeFuture* _tmp1_ = NULL;
	GeeFutureMapFunc _tmp2_ = NULL;
	void* _tmp2__target = NULL;
	GeeFuture* _tmp3_ = NULL;
	g_return_val_if_fail (future_base != NULL, NULL);
	self = (GeeMapFuture*) g_object_new (object_type, NULL);
	self->priv->a_type = a_type;
	self->priv->a_dup_func = a_dup_func;
	self->priv->a_destroy_func = a_destroy_func;
	self->priv->g_type = g_type;
	self->priv->g_dup_func = g_dup_func;
	self->priv->g_destroy_func = g_destroy_func;
	_tmp0_ = future_base;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_base);
	self->priv->_base = _tmp1_;
	_tmp2_ = func;
	_tmp2__target = func_target;
	(self->priv->_func_target_destroy_notify == NULL) ? NULL : (self->priv->_func_target_destroy_notify (self->priv->_func_target), NULL);
	self->priv->_func = NULL;
	self->priv->_func_target = NULL;
	self->priv->_func_target_destroy_notify = NULL;
	self->priv->_func = _tmp2_;
	self->priv->_func_target = _tmp2__target;
	self->priv->_func_target_destroy_notify = NULL;
	_tmp3_ = self->priv->_base;
	gee_future_when_done (_tmp3_, ___lambda40__gee_future_when_done_func, g_object_ref (self));
	return self;
}


GeeMapFuture* gee_map_future_new (GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeFuture* future_base, GeeFutureMapFunc func, void* func_target) {
	return gee_map_future_construct (GEE_TYPE_MAP_FUTURE, a_type, a_dup_func, a_destroy_func, g_type, g_dup_func, g_destroy_func, future_base, func, func_target);
}


static gconstpointer gee_map_future_real_wait (GeeFuture* base) {
	GeeMapFuture * self;
	gconstpointer result = NULL;
	GeeMapFutureProgress progress = 0;
	GeeMapFutureProgress _tmp0_ = 0;
	GeeMapFutureProgress _tmp1_ = 0;
	GeeMapFutureProgress _tmp5_ = 0;
	GeeMapFutureProgress _tmp7_ = 0;
	self = (GeeMapFuture*) base;
	g_mutex_lock (&self->priv->_mutex);
	_tmp0_ = self->priv->_progress;
	progress = _tmp0_;
	_tmp1_ = progress;
	if (_tmp1_ == GEE_MAP_FUTURE_PROGRESS_INIT) {
		GeeFuture* base_future = NULL;
		GeeFuture* _tmp2_ = NULL;
		GeeFuture* _tmp3_ = NULL;
		GeeFuture* _tmp4_ = NULL;
		_tmp2_ = self->priv->_base;
		_tmp3_ = _g_object_ref0 (_tmp2_);
		base_future = _tmp3_;
		g_mutex_unlock (&self->priv->_mutex);
		_tmp4_ = base_future;
		gee_future_wait (_tmp4_);
		g_mutex_lock (&self->priv->_mutex);
		progress = GEE_MAP_FUTURE_PROGRESS_PROGRESS;
		_g_object_unref0 (base_future);
	}
	_tmp5_ = progress;
	if (_tmp5_ == GEE_MAP_FUTURE_PROGRESS_PROGRESS) {
		GMutex _tmp6_ = {0};
		_tmp6_ = self->priv->_mutex;
		g_cond_wait (&self->priv->_cond, &_tmp6_);
		progress = GEE_MAP_FUTURE_PROGRESS_READY;
	}
	_tmp7_ = progress;
	if (_tmp7_ == GEE_MAP_FUTURE_PROGRESS_READY) {
		gconstpointer _tmp8_ = NULL;
		g_mutex_unlock (&self->priv->_mutex);
		_tmp8_ = self->priv->_value;
		result = _tmp8_;
		return result;
	}
	g_assert_not_reached ();
}


static gboolean gee_map_future_real_wait_until (GeeFuture* base, gint64 end_time, gconstpointer* value) {
	GeeMapFuture * self;
	gconstpointer _vala_value = NULL;
	gboolean result = FALSE;
	GeeMapFutureProgress progress = 0;
	GeeMapFutureProgress _tmp0_ = 0;
	GeeMapFutureProgress _tmp1_ = 0;
	GeeMapFutureProgress _tmp7_ = 0;
	GeeMapFutureProgress _tmp11_ = 0;
	self = (GeeMapFuture*) base;
	g_mutex_lock (&self->priv->_mutex);
	_tmp0_ = self->priv->_progress;
	progress = _tmp0_;
	_tmp1_ = progress;
	if (_tmp1_ == GEE_MAP_FUTURE_PROGRESS_INIT) {
		GeeFuture* base_future = NULL;
		GeeFuture* _tmp2_ = NULL;
		GeeFuture* _tmp3_ = NULL;
		GeeFuture* _tmp4_ = NULL;
		gint64 _tmp5_ = 0LL;
		gboolean _tmp6_ = FALSE;
		_tmp2_ = self->priv->_base;
		_tmp3_ = _g_object_ref0 (_tmp2_);
		base_future = _tmp3_;
		g_mutex_unlock (&self->priv->_mutex);
		_tmp4_ = base_future;
		_tmp5_ = end_time;
		_tmp6_ = gee_future_wait_until (_tmp4_, _tmp5_, NULL);
		if (!_tmp6_) {
			result = FALSE;
			_g_object_unref0 (base_future);
			if (value) {
				*value = _vala_value;
			}
			return result;
		}
		g_mutex_lock (&self->priv->_mutex);
		progress = GEE_MAP_FUTURE_PROGRESS_PROGRESS;
		_g_object_unref0 (base_future);
	}
	_tmp7_ = progress;
	if (_tmp7_ == GEE_MAP_FUTURE_PROGRESS_PROGRESS) {
		GMutex _tmp8_ = {0};
		gint64 _tmp9_ = 0LL;
		gboolean _tmp10_ = FALSE;
		_tmp8_ = self->priv->_mutex;
		_tmp9_ = end_time;
		_tmp10_ = g_cond_wait_until (&self->priv->_cond, &_tmp8_, _tmp9_);
		if (!_tmp10_) {
			g_mutex_unlock (&self->priv->_mutex);
			result = FALSE;
			if (value) {
				*value = _vala_value;
			}
			return result;
		}
		progress = GEE_MAP_FUTURE_PROGRESS_READY;
	}
	_tmp11_ = progress;
	if (_tmp11_ == GEE_MAP_FUTURE_PROGRESS_READY) {
		gconstpointer _tmp12_ = NULL;
		g_mutex_unlock (&self->priv->_mutex);
		_tmp12_ = self->priv->_value;
		_vala_value = _tmp12_;
		result = TRUE;
		if (value) {
			*value = _vala_value;
		}
		return result;
	}
	g_assert_not_reached ();
	if (value) {
		*value = _vala_value;
	}
}


static void gee_map_future_real_wait_async_data_free (gpointer _data) {
	GeeMapFutureWaitAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GeeMapFutureWaitAsyncData, _data_);
}


static void gee_map_future_real_wait_async (GeeFuture* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	GeeMapFuture * self;
	GeeMapFutureWaitAsyncData* _data_;
	GeeMapFuture* _tmp0_ = NULL;
	self = (GeeMapFuture*) base;
	_data_ = g_slice_new0 (GeeMapFutureWaitAsyncData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, gee_map_future_real_wait_async);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, gee_map_future_real_wait_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	gee_map_future_real_wait_async_co (_data_);
}


static gconstpointer gee_map_future_real_wait_finish (GeeFuture* base, GAsyncResult* _res_) {
	gconstpointer result;
	GeeMapFutureWaitAsyncData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static Block9Data* block9_data_ref (Block9Data* _data9_) {
	g_atomic_int_inc (&_data9_->_ref_count_);
	return _data9_;
}


static void block9_data_unref (void * _userdata_) {
	Block9Data* _data9_;
	_data9_ = (Block9Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data9_->_ref_count_)) {
		GeeMapFuture * self;
		self = _data9_->self;
		_g_object_unref0 (self);
		g_slice_free (Block9Data, _data9_);
	}
}


static void gee_map_future_wait_async_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	GeeMapFutureWaitAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	gee_map_future_real_wait_async_co (_data_);
}


static void ___lambda41_ (Block9Data* _data9_, gconstpointer res) {
	GeeMapFuture * self;
	self = _data9_->self;
	gee_map_future_real_wait_async_co (_data9_->_async_data_);
}


static void ____lambda41__gee_future_when_done_func (gconstpointer value, gpointer self) {
	___lambda41_ (self, value);
	block9_data_unref (self);
}


static void _vala_array_add3 (GeeFutureWhenDoneArrayElement** array, int* length, int* size, const GeeFutureWhenDoneArrayElement* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GeeFutureWhenDoneArrayElement, *array, *size);
	}
	(*array)[(*length)++] = *value;
}


static gboolean gee_map_future_real_wait_async_co (GeeMapFutureWaitAsyncData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data9_ = g_slice_new0 (Block9Data);
	_data_->_data9_->_ref_count_ = 1;
	_data_->_data9_->self = g_object_ref (_data_->self);
	_data_->_data9_->_async_data_ = _data_;
	g_mutex_lock (&_data_->self->priv->_mutex);
	_data_->_tmp0_ = 0;
	_data_->_tmp0_ = _data_->self->priv->_progress;
	_data_->progress = _data_->_tmp0_;
	_data_->_tmp1_ = 0;
	_data_->_tmp1_ = _data_->progress;
	if (_data_->_tmp1_ == GEE_MAP_FUTURE_PROGRESS_INIT) {
		_data_->_tmp2_ = NULL;
		_data_->_tmp2_ = _data_->self->priv->_base;
		_data_->_tmp3_ = NULL;
		_data_->_tmp3_ = _g_object_ref0 (_data_->_tmp2_);
		_data_->base_future = _data_->_tmp3_;
		g_mutex_unlock (&_data_->self->priv->_mutex);
		_data_->_tmp4_ = NULL;
		_data_->_tmp4_ = _data_->base_future;
		_data_->_state_ = 1;
		gee_future_wait_async (_data_->_tmp4_, gee_map_future_wait_async_ready, _data_);
		return FALSE;
		_state_1:
		gee_future_wait_finish (_data_->_tmp4_, _data_->_res_);
		g_mutex_lock (&_data_->self->priv->_mutex);
		_data_->progress = GEE_MAP_FUTURE_PROGRESS_PROGRESS;
		_g_object_unref0 (_data_->base_future);
	}
	_data_->_tmp5_ = 0;
	_data_->_tmp5_ = _data_->progress;
	if (_data_->_tmp5_ == GEE_MAP_FUTURE_PROGRESS_PROGRESS) {
		_data_->_result_ = NULL;
		_data_->_tmp6_ = NULL;
		_data_->_tmp6__length1 = 0;
		_data_->_tmp6_ = _data_->self->priv->_when_done;
		_data_->_tmp6__length1 = _data_->self->priv->_when_done_length1;
		memset (&_data_->_tmp7_, 0, sizeof (GeeFutureWhenDoneArrayElement));
		gee_future_when_done_array_element_init (&_data_->_tmp7_, ____lambda41__gee_future_when_done_func, block9_data_ref (_data_->_data9_));
		_vala_array_add3 (&_data_->self->priv->_when_done, &_data_->self->priv->_when_done_length1, &_data_->self->priv->__when_done_size_, &_data_->_tmp7_);
		g_mutex_unlock (&_data_->self->priv->_mutex);
		_data_->_state_ = 2;
		return FALSE;
		_state_2:
		;
		_data_->_tmp8_ = NULL;
		_data_->_tmp8_ = _data_->self->priv->_value;
		_data_->result = _data_->_tmp8_;
		block9_data_unref (_data_->_data9_);
		_data_->_data9_ = NULL;
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp9_ = 0;
	_data_->_tmp9_ = _data_->progress;
	if (_data_->_tmp9_ == GEE_MAP_FUTURE_PROGRESS_READY) {
		g_mutex_unlock (&_data_->self->priv->_mutex);
		_data_->_tmp10_ = NULL;
		_data_->_tmp10_ = _data_->self->priv->_value;
		_data_->result = _data_->_tmp10_;
		block9_data_unref (_data_->_data9_);
		_data_->_data9_ = NULL;
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_assert_not_reached ();
	block9_data_unref (_data_->_data9_);
	_data_->_data9_ = NULL;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void _vala_array_add4 (GeeFutureWhenDoneArrayElement** array, int* length, int* size, const GeeFutureWhenDoneArrayElement* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GeeFutureWhenDoneArrayElement, *array, *size);
	}
	(*array)[(*length)++] = *value;
}


static void gee_map_future_real_when_done (GeeFuture* base, GeeFutureWhenDoneFunc func, void* func_target) {
	GeeMapFuture * self;
	GeeMapFutureProgress _tmp0_ = 0;
	self = (GeeMapFuture*) base;
	g_mutex_lock (&self->priv->_mutex);
	_tmp0_ = self->priv->_progress;
	if (_tmp0_ == GEE_MAP_FUTURE_PROGRESS_READY) {
		GeeFutureWhenDoneFunc _tmp1_ = NULL;
		void* _tmp1__target = NULL;
		gconstpointer _tmp2_ = NULL;
		g_mutex_unlock (&self->priv->_mutex);
		_tmp1_ = func;
		_tmp1__target = func_target;
		_tmp2_ = self->priv->_value;
		_tmp1_ (_tmp2_, _tmp1__target);
	} else {
		GeeFutureWhenDoneArrayElement* _tmp3_ = NULL;
		gint _tmp3__length1 = 0;
		GeeFutureWhenDoneFunc _tmp4_ = NULL;
		void* _tmp4__target = NULL;
		GeeFutureWhenDoneArrayElement _tmp5_ = {0};
		_tmp3_ = self->priv->_when_done;
		_tmp3__length1 = self->priv->_when_done_length1;
		_tmp4_ = func;
		_tmp4__target = func_target;
		gee_future_when_done_array_element_init (&_tmp5_, _tmp4_, _tmp4__target);
		_vala_array_add4 (&self->priv->_when_done, &self->priv->_when_done_length1, &self->priv->__when_done_size_, &_tmp5_);
		g_mutex_unlock (&self->priv->_mutex);
	}
}


static inline gconstpointer gee_map_future_go_map (GeeMapFuture* self, gconstpointer val) {
	gconstpointer result = NULL;
	gpointer tmp_value = NULL;
	GeeFutureMapFunc _tmp0_ = NULL;
	void* _tmp0__target = NULL;
	gconstpointer _tmp1_ = NULL;
	gpointer _tmp2_ = NULL;
	gconstpointer value = NULL;
	gconstpointer _tmp3_ = NULL;
	gpointer _tmp4_ = NULL;
	GeeFutureWhenDoneArrayElement* when_done = NULL;
	GeeFutureWhenDoneArrayElement* _tmp5_ = NULL;
	gint _tmp5__length1 = 0;
	gint when_done_length1 = 0;
	gint _when_done_size_ = 0;
	gconstpointer _tmp16_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	self->priv->_progress = GEE_MAP_FUTURE_PROGRESS_PROGRESS;
	g_mutex_unlock (&self->priv->_mutex);
	_tmp0_ = self->priv->_func;
	_tmp0__target = self->priv->_func_target;
	_tmp1_ = val;
	_tmp2_ = _tmp0_ (_tmp1_, _tmp0__target);
	tmp_value = _tmp2_;
	_tmp3_ = tmp_value;
	value = _tmp3_;
	g_mutex_lock (&self->priv->_mutex);
	_tmp4_ = tmp_value;
	tmp_value = NULL;
	((self->priv->_value == NULL) || (self->priv->a_destroy_func == NULL)) ? NULL : (self->priv->_value = (self->priv->a_destroy_func (self->priv->_value), NULL));
	self->priv->_value = _tmp4_;
	self->priv->_progress = GEE_MAP_FUTURE_PROGRESS_READY;
	g_cond_broadcast (&self->priv->_cond);
	g_mutex_unlock (&self->priv->_mutex);
	_tmp5_ = self->priv->_when_done;
	_tmp5__length1 = self->priv->_when_done_length1;
	self->priv->_when_done = NULL;
	when_done = _tmp5_;
	when_done_length1 = _tmp5__length1;
	_when_done_size_ = when_done_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp6_ = FALSE;
			_tmp6_ = TRUE;
			while (TRUE) {
				gboolean _tmp7_ = FALSE;
				gint _tmp9_ = 0;
				GeeFutureWhenDoneArrayElement* _tmp10_ = NULL;
				gint _tmp10__length1 = 0;
				GeeFutureWhenDoneArrayElement* _tmp11_ = NULL;
				gint _tmp11__length1 = 0;
				gint _tmp12_ = 0;
				GeeFutureWhenDoneArrayElement _tmp13_ = {0};
				GeeFutureWhenDoneFunc _tmp14_ = NULL;
				void* _tmp14__target = NULL;
				gconstpointer _tmp15_ = NULL;
				_tmp7_ = _tmp6_;
				if (!_tmp7_) {
					gint _tmp8_ = 0;
					_tmp8_ = i;
					i = _tmp8_ + 1;
				}
				_tmp6_ = FALSE;
				_tmp9_ = i;
				_tmp10_ = when_done;
				_tmp10__length1 = when_done_length1;
				if (!(_tmp9_ < _tmp10__length1)) {
					break;
				}
				_tmp11_ = when_done;
				_tmp11__length1 = when_done_length1;
				_tmp12_ = i;
				_tmp13_ = _tmp11_[_tmp12_];
				_tmp14_ = _tmp13_.func;
				_tmp14__target = _tmp13_.func_target;
				_tmp15_ = value;
				_tmp14_ (_tmp15_, _tmp14__target);
			}
		}
	}
	_g_object_unref0 (self->priv->_base);
	self->priv->_base = NULL;
	(self->priv->_func_target_destroy_notify == NULL) ? NULL : (self->priv->_func_target_destroy_notify (self->priv->_func_target), NULL);
	self->priv->_func = NULL;
	self->priv->_func_target = NULL;
	self->priv->_func_target_destroy_notify = NULL;
	self->priv->_func = NULL;
	self->priv->_func_target = NULL;
	self->priv->_func_target_destroy_notify = NULL;
	_tmp16_ = value;
	result = _tmp16_;
	when_done = (_vala_GeeFutureWhenDoneArrayElement_array_free (when_done, when_done_length1), NULL);
	((tmp_value == NULL) || (self->priv->a_destroy_func == NULL)) ? NULL : (tmp_value = (self->priv->a_destroy_func (tmp_value), NULL));
	return result;
}


static gboolean gee_map_future_real_get_ready (GeeFuture* base) {
	gboolean result;
	GeeMapFuture* self;
	gboolean _result_ = FALSE;
	GeeMapFutureProgress _tmp0_ = 0;
	self = (GeeMapFuture*) base;
	g_mutex_lock (&self->priv->_mutex);
	_tmp0_ = self->priv->_progress;
	_result_ = _tmp0_ == GEE_MAP_FUTURE_PROGRESS_READY;
	g_mutex_unlock (&self->priv->_mutex);
	result = _result_;
	return result;
}


static void gee_map_future_class_init (GeeMapFutureClass * klass) {
	gee_map_future_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GeeMapFuturePrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_gee_map_future_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gee_map_future_set_property;
	G_OBJECT_CLASS (klass)->finalize = gee_map_future_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_MAP_FUTURE_A_TYPE, g_param_spec_gtype ("a-type", "type", "type", G_TYPE_NONE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_MAP_FUTURE_A_DUP_FUNC, g_param_spec_pointer ("a-dup-func", "dup func", "dup func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_MAP_FUTURE_A_DESTROY_FUNC, g_param_spec_pointer ("a-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_MAP_FUTURE_G_TYPE, g_param_spec_gtype ("g-type", "type", "type", G_TYPE_NONE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_MAP_FUTURE_G_DUP_FUNC, g_param_spec_pointer ("g-dup-func", "dup func", "dup func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_MAP_FUTURE_G_DESTROY_FUNC, g_param_spec_pointer ("g-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_MAP_FUTURE_READY, g_param_spec_boolean ("ready", "ready", "ready", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
}


static GType gee_map_future_gee_future_get_g_type (GeeMapFuture* self) {
	return self->priv->a_type;
}


static GBoxedCopyFunc gee_map_future_gee_future_get_g_dup_func (GeeMapFuture* self) {
	return self->priv->a_dup_func;
}


static GDestroyNotify gee_map_future_gee_future_get_g_destroy_func (GeeMapFuture* self) {
	return self->priv->a_destroy_func;
}


static void gee_map_future_gee_future_interface_init (GeeFutureIface * iface) {
	gee_map_future_gee_future_parent_iface = g_type_interface_peek_parent (iface);
	iface->wait = (gconstpointer (*)(GeeFuture*)) gee_map_future_real_wait;
	iface->wait_until = (gboolean (*)(GeeFuture*, gint64, gconstpointer*)) gee_map_future_real_wait_until;
	iface->wait_async = (gconstpointer (*)(GeeFuture*)) gee_map_future_real_wait_async;
	iface->wait_finish = gee_map_future_real_wait_finish;
	iface->when_done = (void (*)(GeeFuture*, GeeFutureWhenDoneFunc, void*)) gee_map_future_real_when_done;
	iface->get_g_type = (GType(*)(GeeFuture*)) gee_map_future_gee_future_get_g_type;
	iface->get_g_dup_func = (GBoxedCopyFunc(*)(GeeFuture*)) gee_map_future_gee_future_get_g_dup_func;
	iface->get_g_destroy_func = (GDestroyNotify(*)(GeeFuture*)) gee_map_future_gee_future_get_g_destroy_func;
	iface->get_ready = gee_map_future_real_get_ready;
}


static void gee_map_future_instance_init (GeeMapFuture * self) {
	GMutex _tmp0_ = {0};
	GCond _tmp1_ = {0};
	GeeFutureWhenDoneArrayElement* _tmp2_ = NULL;
	self->priv = GEE_MAP_FUTURE_GET_PRIVATE (self);
	g_mutex_init (&_tmp0_);
	self->priv->_mutex = _tmp0_;
	g_cond_init (&_tmp1_);
	self->priv->_cond = _tmp1_;
	self->priv->_progress = GEE_MAP_FUTURE_PROGRESS_INIT;
	_tmp2_ = g_new0 (GeeFutureWhenDoneArrayElement, 0);
	self->priv->_when_done = _tmp2_;
	self->priv->_when_done_length1 = 0;
	self->priv->__when_done_size_ = self->priv->_when_done_length1;
}


static void gee_map_future_finalize (GObject* obj) {
	GeeMapFuture * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEE_TYPE_MAP_FUTURE, GeeMapFuture);
	_vala_clear_GMutex (&self->priv->_mutex);
	_vala_clear_GCond (&self->priv->_cond);
	_g_object_unref0 (self->priv->_base);
	(self->priv->_func_target_destroy_notify == NULL) ? NULL : (self->priv->_func_target_destroy_notify (self->priv->_func_target), NULL);
	self->priv->_func = NULL;
	self->priv->_func_target = NULL;
	self->priv->_func_target_destroy_notify = NULL;
	((self->priv->_value == NULL) || (self->priv->a_destroy_func == NULL)) ? NULL : (self->priv->_value = (self->priv->a_destroy_func (self->priv->_value), NULL));
	self->priv->_when_done = (_vala_GeeFutureWhenDoneArrayElement_array_free (self->priv->_when_done, self->priv->_when_done_length1), NULL);
	G_OBJECT_CLASS (gee_map_future_parent_class)->finalize (obj);
}


GType gee_map_future_get_type (void) {
	static volatile gsize gee_map_future_type_id__volatile = 0;
	if (g_once_init_enter (&gee_map_future_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GeeMapFutureClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gee_map_future_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GeeMapFuture), 0, (GInstanceInitFunc) gee_map_future_instance_init, NULL };
		static const GInterfaceInfo gee_future_info = { (GInterfaceInitFunc) gee_map_future_gee_future_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType gee_map_future_type_id;
		gee_map_future_type_id = g_type_register_static (G_TYPE_OBJECT, "GeeMapFuture", &g_define_type_info, 0);
		g_type_add_interface_static (gee_map_future_type_id, GEE_TYPE_FUTURE, &gee_future_info);
		g_once_init_leave (&gee_map_future_type_id__volatile, gee_map_future_type_id);
	}
	return gee_map_future_type_id__volatile;
}


static void _vala_gee_map_future_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	GeeMapFuture * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEE_TYPE_MAP_FUTURE, GeeMapFuture);
	switch (property_id) {
		case GEE_MAP_FUTURE_READY:
		g_value_set_boolean (value, gee_future_get_ready ((GeeFuture*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_gee_map_future_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	GeeMapFuture * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEE_TYPE_MAP_FUTURE, GeeMapFuture);
	switch (property_id) {
		case GEE_MAP_FUTURE_A_TYPE:
		self->priv->a_type = g_value_get_gtype (value);
		break;
		case GEE_MAP_FUTURE_A_DUP_FUNC:
		self->priv->a_dup_func = g_value_get_pointer (value);
		break;
		case GEE_MAP_FUTURE_A_DESTROY_FUNC:
		self->priv->a_destroy_func = g_value_get_pointer (value);
		break;
		case GEE_MAP_FUTURE_G_TYPE:
		self->priv->g_type = g_value_get_gtype (value);
		break;
		case GEE_MAP_FUTURE_G_DUP_FUNC:
		self->priv->g_dup_func = g_value_get_pointer (value);
		break;
		case GEE_MAP_FUTURE_G_DESTROY_FUNC:
		self->priv->g_destroy_func = g_value_get_pointer (value);
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_clear_GMutex (GMutex * mutex) {
	GMutex zero_mutex = { 0 };
	if (memcmp (mutex, &zero_mutex, sizeof (GMutex))) {
		g_mutex_clear (mutex);
		memset (mutex, 0, sizeof (GMutex));
	}
}


static void _vala_clear_GRecMutex (GRecMutex * mutex) {
	GRecMutex zero_mutex = { 0 };
	if (memcmp (mutex, &zero_mutex, sizeof (GRecMutex))) {
		g_rec_mutex_clear (mutex);
		memset (mutex, 0, sizeof (GRecMutex));
	}
}


static void _vala_clear_GRWLock (GRWLock * mutex) {
	GRWLock zero_mutex = { 0 };
	if (memcmp (mutex, &zero_mutex, sizeof (GRWLock))) {
		g_rw_lock_clear (mutex);
		memset (mutex, 0, sizeof (GRWLock));
	}
}


static void _vala_clear_GCond (GCond * mutex) {
	GCond zero_mutex = { 0 };
	if (memcmp (mutex, &zero_mutex, sizeof (GCond))) {
		g_cond_clear (mutex);
		memset (mutex, 0, sizeof (GCond));
	}
}



