/* async-task.c generated by valac 0.56.19, the Vala compiler
 * generated from async-task.vala, do not modify */

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

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define G4_TYPE_EVENT (g4_event_get_type ())
#define G4_EVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G4_TYPE_EVENT, G4Event))
#define G4_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G4_TYPE_EVENT, G4EventClass))
#define G4_IS_EVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G4_TYPE_EVENT))
#define G4_IS_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G4_TYPE_EVENT))
#define G4_EVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G4_TYPE_EVENT, G4EventClass))

typedef struct _G4Event G4Event;
typedef struct _G4EventClass G4EventClass;
typedef struct _G4EventPrivate G4EventPrivate;
typedef struct _G4ParamSpecEvent G4ParamSpecEvent;
typedef gpointer (*G4TaskFunc) (gpointer user_data);
typedef void (*G4VoidFunc) (gpointer user_data);

#define G4_TYPE_WORKER (g4_worker_get_type ())
#define G4_WORKER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G4_TYPE_WORKER, G4Worker))
#define G4_WORKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G4_TYPE_WORKER, G4WorkerClass))
#define G4_IS_WORKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G4_TYPE_WORKER))
#define G4_IS_WORKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G4_TYPE_WORKER))
#define G4_WORKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G4_TYPE_WORKER, G4WorkerClass))

typedef struct _G4Worker G4Worker;
typedef struct _G4WorkerClass G4WorkerClass;
typedef struct _G4WorkerPrivate G4WorkerPrivate;
#define _g4_worker_unref0(var) ((var == NULL) ? NULL : (var = (g4_worker_unref (var), NULL)))
#define _g_thread_pool_free0(var) ((var == NULL) ? NULL : (var = (g_thread_pool_free (var, FALSE, TRUE), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _G4ParamSpecWorker G4ParamSpecWorker;
typedef struct _G4RunAsyncData G4RunAsyncData;
typedef struct _Block47Data Block47Data;
typedef struct _Block48Data Block48Data;
typedef struct _G4RunVoidAsyncData G4RunVoidAsyncData;

struct _G4Event {
	GTypeInstance parent_instance;
	volatile int ref_count;
	G4EventPrivate * priv;
};

struct _G4EventClass {
	GTypeClass parent_class;
	void (*finalize) (G4Event *self);
};

struct _G4EventPrivate {
	GCond _cond;
	GMutex _mutex;
	gboolean _notified;
};

struct _G4ParamSpecEvent {
	GParamSpec parent_instance;
};

struct _G4Worker {
	GTypeInstance parent_instance;
	volatile int ref_count;
	G4WorkerPrivate * priv;
};

struct _G4WorkerClass {
	GTypeClass parent_class;
	void (*finalize) (G4Worker *self);
};

struct _G4WorkerPrivate {
	GType v_type;
	GBoxedCopyFunc v_dup_func;
	GDestroyNotify v_destroy_func;
	G4TaskFunc _task;
	gpointer _task_target;
	GDestroyNotify _task_target_destroy_notify;
	GSourceFunc _callback;
	gpointer _callback_target;
	GDestroyNotify _callback_target_destroy_notify;
	gpointer _result;
};

struct _G4ParamSpecWorker {
	GParamSpec parent_instance;
};

struct _G4RunAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	G4TaskFunc task;
	gpointer task_target;
	gboolean front;
	gboolean in_single_pool;
	GType v_type;
	GBoxedCopyFunc v_dup_func;
	GDestroyNotify v_destroy_func;
	gpointer result;
	G4Worker* worker;
	G4Worker* _tmp0_;
	GThreadPool* _tmp1_;
	GThreadPool* _tmp2_;
	GThreadPool* _tmp3_;
	GThreadPool* pool;
	G4Worker* _tmp4_;
	G4Worker* _tmp5_;
	G4Worker* _tmp6_;
	G4Worker* _tmp7_;
	gconstpointer _tmp8_;
	gconstpointer _tmp9_;
	gpointer _tmp10_;
	GError* _inner_error0_;
};

struct _Block47Data {
	int _ref_count_;
	G4VoidFunc func;
	gpointer func_target;
	GDestroyNotify func_target_destroy_notify;
};

struct _Block48Data {
	int _ref_count_;
	G4VoidFunc func;
	gpointer func_target;
	GDestroyNotify func_target_destroy_notify;
};

struct _G4RunVoidAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	G4VoidFunc task;
	gpointer task_target;
};

static gint G4Event_private_offset;
static gpointer g4_event_parent_class = NULL;
static gint G4Worker_private_offset;
static gpointer g4_worker_parent_class = NULL;
static GOnce g4_worker_multi_thread_pool;
static GOnce g4_worker_multi_thread_pool = G_ONCE_INIT;
static GOnce g4_worker_single_thread_pool;
static GOnce g4_worker_single_thread_pool = G_ONCE_INIT;

VALA_EXTERN gpointer g4_event_ref (gpointer instance);
VALA_EXTERN void g4_event_unref (gpointer instance);
VALA_EXTERN GParamSpec* g4_param_spec_event (const gchar* name,
                                 const gchar* nick,
                                 const gchar* blurb,
                                 GType object_type,
                                 GParamFlags flags);
VALA_EXTERN void g4_value_set_event (GValue* value,
                         gpointer v_object);
VALA_EXTERN void g4_value_take_event (GValue* value,
                          gpointer v_object);
VALA_EXTERN gpointer g4_value_get_event (const GValue* value);
VALA_EXTERN GType g4_event_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (G4Event, g4_event_unref)
VALA_EXTERN void g4_event_notify (G4Event* self);
VALA_EXTERN void g4_event_reset (G4Event* self);
VALA_EXTERN void g4_event_wait (G4Event* self);
VALA_EXTERN G4Event* g4_event_new (void);
VALA_EXTERN G4Event* g4_event_construct (GType object_type);
static void g4_event_finalize (G4Event * obj);
static GType g4_event_get_type_once (void);
VALA_EXTERN gpointer g4_worker_ref (gpointer instance);
VALA_EXTERN void g4_worker_unref (gpointer instance);
VALA_EXTERN GParamSpec* g4_param_spec_worker (const gchar* name,
                                  const gchar* nick,
                                  const gchar* blurb,
                                  GType object_type,
                                  GParamFlags flags);
VALA_EXTERN void g4_value_set_worker (GValue* value,
                          gpointer v_object);
VALA_EXTERN void g4_value_take_worker (GValue* value,
                           gpointer v_object);
VALA_EXTERN gpointer g4_value_get_worker (const GValue* value);
VALA_EXTERN GType g4_worker_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (G4Worker, g4_worker_unref)
VALA_EXTERN G4Worker* g4_worker_new (GType v_type,
                         GBoxedCopyFunc v_dup_func,
                         GDestroyNotify v_destroy_func,
                         G4TaskFunc task,
                         gpointer task_target,
                         GSourceFunc callback,
                         gpointer callback_target);
VALA_EXTERN G4Worker* g4_worker_construct (GType object_type,
                               GType v_type,
                               GBoxedCopyFunc v_dup_func,
                               GDestroyNotify v_destroy_func,
                               G4TaskFunc task,
                               gpointer task_target,
                               GSourceFunc callback,
                               gpointer callback_target);
static void g4_worker_run (G4Worker* self);
VALA_EXTERN GThreadPool* g4_worker_get_multi_thread_pool (void);
static GThreadPool* __lambda25_ (void);
static GThreadPool* g4_worker_new_thread_pool (guint num_threads);
static gpointer ___lambda25__gthread_func (gpointer self);
VALA_EXTERN GThreadPool* g4_worker_get_single_thread_pool (void);
static GThreadPool* __lambda27_ (void);
static gpointer ___lambda27__gthread_func (gpointer self);
static void ___lambda26_ (G4Worker* tdata);
static void ____lambda26__gfunc (gpointer data,
                          gpointer self);
VALA_EXTERN gconstpointer g4_worker_get_result (G4Worker* self);
static void g4_worker_finalize (G4Worker * obj);
static GType g4_worker_get_type_once (void);
static void g4_run_async_data_free (gpointer _data);
VALA_EXTERN void g4_run_async (GType v_type,
                   GBoxedCopyFunc v_dup_func,
                   GDestroyNotify v_destroy_func,
                   G4TaskFunc task,
                   gpointer task_target,
                   gboolean front,
                   gboolean in_single_pool,
                   GAsyncReadyCallback _callback_,
                   gpointer _user_data_);
VALA_EXTERN gpointer g4_run_finish (GAsyncResult* _res_);
static gboolean g4_run_async_co (G4RunAsyncData* _data_);
static gboolean _g4_run_async_co_gsource_func (gpointer self);
VALA_EXTERN guint g4_run_idle_once (G4VoidFunc func,
                        gpointer func_target,
                        GDestroyNotify func_target_destroy_notify,
                        gint priority);
static Block47Data* block47_data_ref (Block47Data* _data47_);
static void block47_data_unref (void * _userdata_);
static gboolean __lambda43_ (Block47Data* _data47_);
static gboolean ___lambda43__gsource_func (gpointer self);
VALA_EXTERN guint g4_run_timeout_once (guint interval,
                           G4VoidFunc func,
                           gpointer func_target,
                           GDestroyNotify func_target_destroy_notify);
static Block48Data* block48_data_ref (Block48Data* _data48_);
static void block48_data_unref (void * _userdata_);
static gboolean __lambda38_ (Block48Data* _data48_);
static gboolean ___lambda38__gsource_func (gpointer self);
static void g4_run_void_async_data_free (gpointer _data);
VALA_EXTERN void g4_run_void_async (G4VoidFunc task,
                        gpointer task_target,
                        GAsyncReadyCallback _callback_,
                        gpointer _user_data_);
VALA_EXTERN void g4_run_void_finish (GAsyncResult* _res_);
static gboolean g4_run_void_async_co (G4RunVoidAsyncData* _data_);
static void g4_run_void_async_ready (GObject* source_object,
                              GAsyncResult* _res_,
                              gpointer _user_data_);
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 inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
g4_event_get_instance_private (G4Event* self)
{
	return G_STRUCT_MEMBER_P (self, G4Event_private_offset);
}

void
g4_event_notify (G4Event* self)
{
	g_return_if_fail (self != NULL);
	g_mutex_lock (&self->priv->_mutex);
	self->priv->_notified = TRUE;
	g_cond_broadcast (&self->priv->_cond);
	g_mutex_unlock (&self->priv->_mutex);
}

void
g4_event_reset (G4Event* self)
{
	g_return_if_fail (self != NULL);
	g_mutex_lock (&self->priv->_mutex);
	self->priv->_notified = FALSE;
	g_mutex_unlock (&self->priv->_mutex);
}

void
g4_event_wait (G4Event* self)
{
	g_return_if_fail (self != NULL);
	g_mutex_lock (&self->priv->_mutex);
	while (TRUE) {
		if (!(!self->priv->_notified)) {
			break;
		}
		g_cond_wait (&self->priv->_cond, &self->priv->_mutex);
	}
	g_mutex_unlock (&self->priv->_mutex);
}

G4Event*
g4_event_construct (GType object_type)
{
	G4Event* self = NULL;
	self = (G4Event*) g_type_create_instance (object_type);
	return self;
}

G4Event*
g4_event_new (void)
{
	return g4_event_construct (G4_TYPE_EVENT);
}

static void
g4_value_event_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
g4_value_event_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		g4_event_unref (value->data[0].v_pointer);
	}
}

static void
g4_value_event_copy_value (const GValue* src_value,
                           GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = g4_event_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
g4_value_event_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
g4_value_event_collect_value (GValue* value,
                              guint n_collect_values,
                              GTypeCValue* collect_values,
                              guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		G4Event * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = g4_event_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
g4_value_event_lcopy_value (const GValue* value,
                            guint n_collect_values,
                            GTypeCValue* collect_values,
                            guint collect_flags)
{
	G4Event ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = g4_event_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
g4_param_spec_event (const gchar* name,
                     const gchar* nick,
                     const gchar* blurb,
                     GType object_type,
                     GParamFlags flags)
{
	G4ParamSpecEvent* spec;
	g_return_val_if_fail (g_type_is_a (object_type, G4_TYPE_EVENT), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
g4_value_get_event (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, G4_TYPE_EVENT), NULL);
	return value->data[0].v_pointer;
}

void
g4_value_set_event (GValue* value,
                    gpointer v_object)
{
	G4Event * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, G4_TYPE_EVENT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, G4_TYPE_EVENT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		g4_event_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		g4_event_unref (old);
	}
}

void
g4_value_take_event (GValue* value,
                     gpointer v_object)
{
	G4Event * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, G4_TYPE_EVENT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, G4_TYPE_EVENT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		g4_event_unref (old);
	}
}

static void
g4_event_class_init (G4EventClass * klass,
                     gpointer klass_data)
{
	g4_event_parent_class = g_type_class_peek_parent (klass);
	((G4EventClass *) klass)->finalize = g4_event_finalize;
	g_type_class_adjust_private_offset (klass, &G4Event_private_offset);
}

static void
g4_event_instance_init (G4Event * self,
                        gpointer klass)
{
	self->priv = g4_event_get_instance_private (self);
	g_cond_init (&self->priv->_cond);
	g_mutex_init (&self->priv->_mutex);
	self->priv->_notified = FALSE;
	self->ref_count = 1;
}

static void
g4_event_finalize (G4Event * obj)
{
	G4Event * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, G4_TYPE_EVENT, G4Event);
	g_signal_handlers_destroy (self);
	_vala_clear_GCond (&self->priv->_cond);
	_vala_clear_GMutex (&self->priv->_mutex);
}

static GType
g4_event_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { g4_value_event_init, g4_value_event_free_value, g4_value_event_copy_value, g4_value_event_peek_pointer, "p", g4_value_event_collect_value, "p", g4_value_event_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (G4EventClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) g4_event_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (G4Event), 0, (GInstanceInitFunc) g4_event_instance_init, &g_define_type_value_table };
	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) };
	GType g4_event_type_id;
	g4_event_type_id = g_type_register_fundamental (g_type_fundamental_next (), "G4Event", &g_define_type_info, &g_define_type_fundamental_info, 0);
	G4Event_private_offset = g_type_add_instance_private (g4_event_type_id, sizeof (G4EventPrivate));
	return g4_event_type_id;
}

GType
g4_event_get_type (void)
{
	static volatile gsize g4_event_type_id__once = 0;
	if (g_once_init_enter (&g4_event_type_id__once)) {
		GType g4_event_type_id;
		g4_event_type_id = g4_event_get_type_once ();
		g_once_init_leave (&g4_event_type_id__once, g4_event_type_id);
	}
	return g4_event_type_id__once;
}

gpointer
g4_event_ref (gpointer instance)
{
	G4Event * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
g4_event_unref (gpointer instance)
{
	G4Event * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		G4_EVENT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static inline gpointer
g4_worker_get_instance_private (G4Worker* self)
{
	return G_STRUCT_MEMBER_P (self, G4Worker_private_offset);
}

G4Worker*
g4_worker_construct (GType object_type,
                     GType v_type,
                     GBoxedCopyFunc v_dup_func,
                     GDestroyNotify v_destroy_func,
                     G4TaskFunc task,
                     gpointer task_target,
                     GSourceFunc callback,
                     gpointer callback_target)
{
	G4Worker* self = NULL;
	self = (G4Worker*) g_type_create_instance (object_type);
	self->priv->v_type = v_type;
	self->priv->v_dup_func = v_dup_func;
	self->priv->v_destroy_func = v_destroy_func;
	(self->priv->_task_target_destroy_notify == NULL) ? NULL : (self->priv->_task_target_destroy_notify (self->priv->_task_target), NULL);
	self->priv->_task = NULL;
	self->priv->_task_target = NULL;
	self->priv->_task_target_destroy_notify = NULL;
	self->priv->_task = task;
	self->priv->_task_target = task_target;
	self->priv->_task_target_destroy_notify = NULL;
	(self->priv->_callback_target_destroy_notify == NULL) ? NULL : (self->priv->_callback_target_destroy_notify (self->priv->_callback_target), NULL);
	self->priv->_callback = NULL;
	self->priv->_callback_target = NULL;
	self->priv->_callback_target_destroy_notify = NULL;
	self->priv->_callback = callback;
	self->priv->_callback_target = callback_target;
	self->priv->_callback_target_destroy_notify = NULL;
	return self;
}

G4Worker*
g4_worker_new (GType v_type,
               GBoxedCopyFunc v_dup_func,
               GDestroyNotify v_destroy_func,
               G4TaskFunc task,
               gpointer task_target,
               GSourceFunc callback,
               gpointer callback_target)
{
	return g4_worker_construct (G4_TYPE_WORKER, v_type, v_dup_func, v_destroy_func, task, task_target, callback, callback_target);
}

static void
g4_worker_run (G4Worker* self)
{
	G4TaskFunc _tmp0_;
	gpointer _tmp0__target;
	gpointer _tmp1_;
	GSourceFunc _tmp2_;
	gpointer _tmp2__target;
	GDestroyNotify _tmp2__target_destroy_notify;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_task;
	_tmp0__target = self->priv->_task_target;
	_tmp1_ = _tmp0_ (_tmp0__target);
	((self->priv->_result == NULL) || (self->priv->v_destroy_func == NULL)) ? NULL : (self->priv->_result = (self->priv->v_destroy_func (self->priv->_result), NULL));
	self->priv->_result = _tmp1_;
	_tmp2_ = self->priv->_callback;
	_tmp2__target = self->priv->_callback_target;
	_tmp2__target_destroy_notify = self->priv->_callback_target_destroy_notify;
	self->priv->_callback = NULL;
	self->priv->_callback_target = NULL;
	self->priv->_callback_target_destroy_notify = NULL;
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _tmp2_, _tmp2__target, _tmp2__target_destroy_notify);
}

static GThreadPool*
__lambda25_ (void)
{
	GThreadPool* _tmp0_;
	GThreadPool* result;
	_tmp0_ = g4_worker_new_thread_pool (g_get_num_processors ());
	result = _tmp0_;
	return result;
}

static gpointer
___lambda25__gthread_func (gpointer self)
{
	gpointer result;
	result = __lambda25_ ();
	return result;
}

GThreadPool*
g4_worker_get_multi_thread_pool (void)
{
	gconstpointer _tmp0_;
	GThreadPool* result;
	_tmp0_ = g_once (&g4_worker_multi_thread_pool, ___lambda25__gthread_func, NULL);
	result = (GThreadPool*) _tmp0_;
	return result;
}

static GThreadPool*
__lambda27_ (void)
{
	GThreadPool* _tmp0_;
	GThreadPool* result;
	_tmp0_ = g4_worker_new_thread_pool ((guint) 1);
	result = _tmp0_;
	return result;
}

static gpointer
___lambda27__gthread_func (gpointer self)
{
	gpointer result;
	result = __lambda27_ ();
	return result;
}

GThreadPool*
g4_worker_get_single_thread_pool (void)
{
	gconstpointer _tmp0_;
	GThreadPool* result;
	_tmp0_ = g_once (&g4_worker_single_thread_pool, ___lambda27__gthread_func, NULL);
	result = (GThreadPool*) _tmp0_;
	return result;
}

static void
___lambda26_ (G4Worker* tdata)
{
	g_return_if_fail (tdata != NULL);
	g4_worker_run (tdata);
	_g4_worker_unref0 (tdata);
}

static void
____lambda26__gfunc (gpointer data,
                     gpointer self)
{
	___lambda26_ ((G4Worker*) data);
}

static GThreadPool*
g4_worker_new_thread_pool (guint num_threads)
{
	GError* _inner_error0_ = NULL;
	GThreadPool* result;
	{
		GThreadPool* _tmp0_ = NULL;
		GThreadPool* _tmp1_;
		GThreadPool* _tmp2_;
		_tmp1_ = g_thread_pool_new (____lambda26__gfunc, NULL, (gint) num_threads, FALSE, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		result = _tmp2_;
		_g_thread_pool_free0 (_tmp0_);
		return result;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp3_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = e->message;
		g_critical ("async-task.vala:67: Create %u threads pool failed: %s\n", num_threads, _tmp3_);
		abort ();
		_g_error_free0 (e);
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

gconstpointer
g4_worker_get_result (G4Worker* self)
{
	gconstpointer result;
	gconstpointer _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_result;
	result = _tmp0_;
	return result;
}

static void
g4_value_worker_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
g4_value_worker_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		g4_worker_unref (value->data[0].v_pointer);
	}
}

static void
g4_value_worker_copy_value (const GValue* src_value,
                            GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = g4_worker_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
g4_value_worker_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
g4_value_worker_collect_value (GValue* value,
                               guint n_collect_values,
                               GTypeCValue* collect_values,
                               guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		G4Worker * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = g4_worker_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
g4_value_worker_lcopy_value (const GValue* value,
                             guint n_collect_values,
                             GTypeCValue* collect_values,
                             guint collect_flags)
{
	G4Worker ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = g4_worker_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
g4_param_spec_worker (const gchar* name,
                      const gchar* nick,
                      const gchar* blurb,
                      GType object_type,
                      GParamFlags flags)
{
	G4ParamSpecWorker* spec;
	g_return_val_if_fail (g_type_is_a (object_type, G4_TYPE_WORKER), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
g4_value_get_worker (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, G4_TYPE_WORKER), NULL);
	return value->data[0].v_pointer;
}

void
g4_value_set_worker (GValue* value,
                     gpointer v_object)
{
	G4Worker * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, G4_TYPE_WORKER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, G4_TYPE_WORKER));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		g4_worker_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		g4_worker_unref (old);
	}
}

void
g4_value_take_worker (GValue* value,
                      gpointer v_object)
{
	G4Worker * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, G4_TYPE_WORKER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, G4_TYPE_WORKER));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		g4_worker_unref (old);
	}
}

static void
g4_worker_class_init (G4WorkerClass * klass,
                      gpointer klass_data)
{
	g4_worker_parent_class = g_type_class_peek_parent (klass);
	((G4WorkerClass *) klass)->finalize = g4_worker_finalize;
	g_type_class_adjust_private_offset (klass, &G4Worker_private_offset);
}

static void
g4_worker_instance_init (G4Worker * self,
                         gpointer klass)
{
	self->priv = g4_worker_get_instance_private (self);
	self->priv->_result = NULL;
	self->ref_count = 1;
}

static void
g4_worker_finalize (G4Worker * obj)
{
	G4Worker * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, G4_TYPE_WORKER, G4Worker);
	g_signal_handlers_destroy (self);
	(self->priv->_task_target_destroy_notify == NULL) ? NULL : (self->priv->_task_target_destroy_notify (self->priv->_task_target), NULL);
	self->priv->_task = NULL;
	self->priv->_task_target = NULL;
	self->priv->_task_target_destroy_notify = NULL;
	(self->priv->_callback_target_destroy_notify == NULL) ? NULL : (self->priv->_callback_target_destroy_notify (self->priv->_callback_target), NULL);
	self->priv->_callback = NULL;
	self->priv->_callback_target = NULL;
	self->priv->_callback_target_destroy_notify = NULL;
	((self->priv->_result == NULL) || (self->priv->v_destroy_func == NULL)) ? NULL : (self->priv->_result = (self->priv->v_destroy_func (self->priv->_result), NULL));
}

static GType
g4_worker_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { g4_value_worker_init, g4_value_worker_free_value, g4_value_worker_copy_value, g4_value_worker_peek_pointer, "p", g4_value_worker_collect_value, "p", g4_value_worker_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (G4WorkerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) g4_worker_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (G4Worker), 0, (GInstanceInitFunc) g4_worker_instance_init, &g_define_type_value_table };
	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) };
	GType g4_worker_type_id;
	g4_worker_type_id = g_type_register_fundamental (g_type_fundamental_next (), "G4Worker", &g_define_type_info, &g_define_type_fundamental_info, 0);
	G4Worker_private_offset = g_type_add_instance_private (g4_worker_type_id, sizeof (G4WorkerPrivate));
	return g4_worker_type_id;
}

GType
g4_worker_get_type (void)
{
	static volatile gsize g4_worker_type_id__once = 0;
	if (g_once_init_enter (&g4_worker_type_id__once)) {
		GType g4_worker_type_id;
		g4_worker_type_id = g4_worker_get_type_once ();
		g_once_init_leave (&g4_worker_type_id__once, g4_worker_type_id);
	}
	return g4_worker_type_id__once;
}

gpointer
g4_worker_ref (gpointer instance)
{
	G4Worker * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
g4_worker_unref (gpointer instance)
{
	G4Worker * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		G4_WORKER_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
g4_run_async_data_free (gpointer _data)
{
	G4RunAsyncData* _data_;
	_data_ = _data;
	((_data_->result == NULL) || (_data_->v_destroy_func == NULL)) ? NULL : (_data_->result = (_data_->v_destroy_func (_data_->result), NULL));
	g_slice_free (G4RunAsyncData, _data_);
}

void
g4_run_async (GType v_type,
              GBoxedCopyFunc v_dup_func,
              GDestroyNotify v_destroy_func,
              G4TaskFunc task,
              gpointer task_target,
              gboolean front,
              gboolean in_single_pool,
              GAsyncReadyCallback _callback_,
              gpointer _user_data_)
{
	G4RunAsyncData* _data_;
	_data_ = g_slice_new0 (G4RunAsyncData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, g4_run_async_data_free);
	_data_->task = task;
	_data_->task_target = task_target;
	_data_->front = front;
	_data_->in_single_pool = in_single_pool;
	_data_->v_type = v_type;
	_data_->v_dup_func = v_dup_func;
	_data_->v_destroy_func = v_destroy_func;
	g4_run_async_co (_data_);
}

gpointer
g4_run_finish (GAsyncResult* _res_)
{
	gpointer result;
	G4RunAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gboolean
_g4_run_async_co_gsource_func (gpointer self)
{
	gboolean result;
	result = g4_run_async_co (self);
	return result;
}

static gpointer
_g4_worker_ref0 (gpointer self)
{
	return self ? g4_worker_ref (self) : NULL;
}

static gboolean
g4_run_async_co (G4RunAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g4_worker_new (_data_->v_type, (GBoxedCopyFunc) _data_->v_dup_func, (GDestroyNotify) _data_->v_destroy_func, _data_->task, _data_->task_target, _g4_run_async_co_gsource_func, _data_);
	_data_->worker = _data_->_tmp0_;
	{
		if (_data_->in_single_pool) {
			_data_->_tmp2_ = g4_worker_get_single_thread_pool ();
			_data_->_tmp1_ = _data_->_tmp2_;
		} else {
			_data_->_tmp3_ = g4_worker_get_multi_thread_pool ();
			_data_->_tmp1_ = _data_->_tmp3_;
		}
		_data_->pool = _data_->_tmp1_;
		_data_->_tmp4_ = _data_->worker;
		_data_->_tmp5_ = _g4_worker_ref0 (_data_->_tmp4_);
		g_thread_pool_push (_data_->pool, _data_->_tmp5_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		if (_data_->front) {
			_data_->_tmp6_ = _data_->worker;
			g_thread_pool_move_to_front (_data_->pool, _data_->_tmp6_);
		}
		_data_->_state_ = 1;
		return FALSE;
		_state_1:
		;
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g4_worker_unref0 (_data_->worker);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp7_ = _data_->worker;
	_data_->_tmp8_ = g4_worker_get_result (_data_->_tmp7_);
	_data_->_tmp9_ = _data_->_tmp8_;
	_data_->_tmp10_ = ((_data_->_tmp9_ != NULL) && (_data_->v_dup_func != NULL)) ? _data_->v_dup_func ((gpointer) _data_->_tmp9_) : ((gpointer) _data_->_tmp9_);
	_data_->result = _data_->_tmp10_;
	_g4_worker_unref0 (_data_->worker);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static Block47Data*
block47_data_ref (Block47Data* _data47_)
{
	g_atomic_int_inc (&_data47_->_ref_count_);
	return _data47_;
}

static void
block47_data_unref (void * _userdata_)
{
	Block47Data* _data47_;
	_data47_ = (Block47Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data47_->_ref_count_)) {
		(_data47_->func_target_destroy_notify == NULL) ? NULL : (_data47_->func_target_destroy_notify (_data47_->func_target), NULL);
		_data47_->func = NULL;
		_data47_->func_target = NULL;
		_data47_->func_target_destroy_notify = NULL;
		g_slice_free (Block47Data, _data47_);
	}
}

static gboolean
__lambda43_ (Block47Data* _data47_)
{
	gboolean result;
	_data47_->func (_data47_->func_target);
	result = FALSE;
	return result;
}

static gboolean
___lambda43__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda43_ (self);
	return result;
}

guint
g4_run_idle_once (G4VoidFunc func,
                  gpointer func_target,
                  GDestroyNotify func_target_destroy_notify,
                  gint priority)
{
	Block47Data* _data47_;
	guint result;
	_data47_ = g_slice_new0 (Block47Data);
	_data47_->_ref_count_ = 1;
	(_data47_->func_target_destroy_notify == NULL) ? NULL : (_data47_->func_target_destroy_notify (_data47_->func_target), NULL);
	_data47_->func = NULL;
	_data47_->func_target = NULL;
	_data47_->func_target_destroy_notify = NULL;
	_data47_->func = func;
	_data47_->func_target = func_target;
	_data47_->func_target_destroy_notify = func_target_destroy_notify;
	result = g_idle_add_full (priority, ___lambda43__gsource_func, block47_data_ref (_data47_), block47_data_unref);
	block47_data_unref (_data47_);
	_data47_ = NULL;
	return result;
}

static Block48Data*
block48_data_ref (Block48Data* _data48_)
{
	g_atomic_int_inc (&_data48_->_ref_count_);
	return _data48_;
}

static void
block48_data_unref (void * _userdata_)
{
	Block48Data* _data48_;
	_data48_ = (Block48Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data48_->_ref_count_)) {
		(_data48_->func_target_destroy_notify == NULL) ? NULL : (_data48_->func_target_destroy_notify (_data48_->func_target), NULL);
		_data48_->func = NULL;
		_data48_->func_target = NULL;
		_data48_->func_target_destroy_notify = NULL;
		g_slice_free (Block48Data, _data48_);
	}
}

static gboolean
__lambda38_ (Block48Data* _data48_)
{
	gboolean result;
	_data48_->func (_data48_->func_target);
	result = FALSE;
	return result;
}

static gboolean
___lambda38__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda38_ (self);
	return result;
}

guint
g4_run_timeout_once (guint interval,
                     G4VoidFunc func,
                     gpointer func_target,
                     GDestroyNotify func_target_destroy_notify)
{
	Block48Data* _data48_;
	guint result;
	_data48_ = g_slice_new0 (Block48Data);
	_data48_->_ref_count_ = 1;
	(_data48_->func_target_destroy_notify == NULL) ? NULL : (_data48_->func_target_destroy_notify (_data48_->func_target), NULL);
	_data48_->func = NULL;
	_data48_->func_target = NULL;
	_data48_->func_target_destroy_notify = NULL;
	_data48_->func = func;
	_data48_->func_target = func_target;
	_data48_->func_target_destroy_notify = func_target_destroy_notify;
	result = g_timeout_add_full (G_PRIORITY_DEFAULT, interval, ___lambda38__gsource_func, block48_data_ref (_data48_), block48_data_unref);
	block48_data_unref (_data48_);
	_data48_ = NULL;
	return result;
}

static void
g4_run_void_async_data_free (gpointer _data)
{
	G4RunVoidAsyncData* _data_;
	_data_ = _data;
	g_slice_free (G4RunVoidAsyncData, _data_);
}

void
g4_run_void_async (G4VoidFunc task,
                   gpointer task_target,
                   GAsyncReadyCallback _callback_,
                   gpointer _user_data_)
{
	G4RunVoidAsyncData* _data_;
	_data_ = g_slice_new0 (G4RunVoidAsyncData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, g4_run_void_async_data_free);
	_data_->task = task;
	_data_->task_target = task_target;
	g4_run_void_async_co (_data_);
}

void
g4_run_void_finish (GAsyncResult* _res_)
{
	G4RunVoidAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
g4_run_void_async_ready (GObject* source_object,
                         GAsyncResult* _res_,
                         gpointer _user_data_)
{
	G4RunVoidAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	g4_run_void_async_co (_data_);
}

static gboolean
g4_run_void_async_co (G4RunVoidAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	g4_run_async (G_TYPE_NONE, NULL, NULL, _data_->task, _data_->task_target, FALSE, FALSE, g4_run_void_async_ready, _data_);
	return FALSE;
	_state_1:
	g4_run_finish (_data_->_res_);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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));
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

