+typedef enum
+{
+ G_THREAD_PRIORITY_LOW,
+ G_THREAD_PRIORITY_NORMAL,
+ G_THREAD_PRIORITY_HIGH,
+ G_THREAD_PRIORITY_URGENT
+} GThreadPriority;
+
+typedef struct _GThread GThread;
+struct _GThread
+{
+ GThreadPriority priority;
+ gboolean bound;
+ gboolean joinable;
+};
+
+typedef struct _GMutex GMutex;
+typedef struct _GCond GCond;
+typedef struct _GPrivate GPrivate;
+typedef struct _GStaticPrivate GStaticPrivate;
+typedef struct _GAsyncQueue GAsyncQueue;
+typedef struct _GThreadPool GThreadPool;
+
+typedef struct _GThreadFunctions GThreadFunctions;
+struct _GThreadFunctions
+{
+ GMutex* (*mutex_new) (void);
+ void (*mutex_lock) (GMutex *mutex);
+ gboolean (*mutex_trylock) (GMutex *mutex);
+ void (*mutex_unlock) (GMutex *mutex);
+ void (*mutex_free) (GMutex *mutex);
+ GCond* (*cond_new) (void);
+ void (*cond_signal) (GCond *cond);
+ void (*cond_broadcast) (GCond *cond);
+ void (*cond_wait) (GCond *cond,
+ GMutex *mutex);
+ gboolean (*cond_timed_wait) (GCond *cond,
+ GMutex *mutex,
+ GTimeVal *end_time);
+ void (*cond_free) (GCond *cond);
+ GPrivate* (*private_new) (GDestroyNotify destructor);
+ gpointer (*private_get) (GPrivate *private_key);
+ void (*private_set) (GPrivate *private_key,
+ gpointer data);
+ void (*thread_create) (GThreadFunc thread_func,
+ gpointer arg,
+ gulong stack_size,
+ gboolean joinable,
+ gboolean bound,
+ GThreadPriority priority,
+ gpointer thread,
+ GError **error);
+ void (*thread_yield) (void);
+ void (*thread_join) (gpointer thread);
+ void (*thread_exit) (void);
+ void (*thread_set_priority)(gpointer thread,
+ GThreadPriority priority);
+ void (*thread_self) (gpointer thread);
+};
+
+GLIB_VAR GThreadFunctions g_thread_functions_for_glib_use;
+GLIB_VAR gboolean g_thread_use_default_impl;
+GLIB_VAR gboolean g_threads_got_initialized;
+
+/* initializes the mutex/cond/private implementation for glib, might
+ * only be called once, and must not be called directly or indirectly
+ * from another glib-function, e.g. as a callback.
+ */
+void g_thread_init (GThreadFunctions *vtable);
+
+/* internal function for fallback static mutex implementation */
+GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
+
+/* shorthands for conditional and unconditional function calls */
+#define G_THREAD_UF(name, arglist) \
+ (*g_thread_functions_for_glib_use . name) arglist
+#define G_THREAD_CF(name, fail, arg) \
+ (g_thread_supported () ? G_THREAD_UF (name, arg) : (fail))
+/* keep in mind, all those mutexes and static mutexes are not
+ * recursive in general, don't rely on that
+ */
+#define g_thread_supported() (g_threads_got_initialized)
+#define g_mutex_new() G_THREAD_UF (mutex_new, ())
+#define g_mutex_lock(mutex) G_THREAD_CF (mutex_lock, (void)0, (mutex))
+#define g_mutex_trylock(mutex) G_THREAD_CF (mutex_trylock, TRUE, (mutex))
+#define g_mutex_unlock(mutex) G_THREAD_CF (mutex_unlock, (void)0, (mutex))
+#define g_mutex_free(mutex) G_THREAD_CF (mutex_free, (void)0, (mutex))
+#define g_cond_new() G_THREAD_UF (cond_new, ())
+#define g_cond_signal(cond) G_THREAD_CF (cond_signal, (void)0, (cond))
+#define g_cond_broadcast(cond) G_THREAD_CF (cond_broadcast, (void)0, (cond))
+#define g_cond_wait(cond, mutex) G_THREAD_CF (cond_wait, (void)0, (cond, \
+ mutex))
+#define g_cond_free(cond) G_THREAD_CF (cond_free, (void)0, (cond))
+#define g_cond_timed_wait(cond, mutex, abs_time) G_THREAD_CF (cond_timed_wait, \
+ TRUE, \
+ (cond, mutex, \
+ abs_time))
+#define g_private_new(destructor) G_THREAD_UF (private_new, (destructor))
+#define g_private_get(private_key) G_THREAD_CF (private_get, \
+ ((gpointer)private_key), \
+ (private_key))
+#define g_private_set(private_key, value) G_THREAD_CF (private_set, \
+ (void) (private_key = \
+ (GPrivate*) (value)), \
+ (private_key, value))
+#define g_thread_yield() G_THREAD_CF (thread_yield, (void)0, ())
+#define g_thread_exit() G_THREAD_CF (thread_exit, (void)0, ())
+
+GThread* g_thread_create (GThreadFunc thread_func,
+ gpointer arg,
+ gulong stack_size,
+ gboolean joinable,
+ gboolean bound,
+ GThreadPriority priority,
+ GError **error);
+GThread* g_thread_self ();
+void g_thread_join (GThread *thread);
+void g_thread_set_priority (GThread *thread,
+ GThreadPriority priority);
+
+/* GStaticMutexes can be statically initialized with the value
+ * G_STATIC_MUTEX_INIT, and then they can directly be used, that is
+ * much easier, than having to explicitly allocate the mutex before
+ * use
+ */
+#define g_static_mutex_lock(mutex) \
+ g_mutex_lock (g_static_mutex_get_mutex (mutex))
+#define g_static_mutex_trylock(mutex) \
+ g_mutex_trylock (g_static_mutex_get_mutex (mutex))
+#define g_static_mutex_unlock(mutex) \
+ g_mutex_unlock (g_static_mutex_get_mutex (mutex))
+
+struct _GStaticPrivate
+{
+ guint index;
+};
+#define G_STATIC_PRIVATE_INIT { 0 }
+gpointer g_static_private_get (GStaticPrivate *private_key);
+void g_static_private_set (GStaticPrivate *private_key,
+ gpointer data,
+ GDestroyNotify notify);
+gpointer g_static_private_get_for_thread (GStaticPrivate *private_key,
+ GThread *thread);
+void g_static_private_set_for_thread (GStaticPrivate *private_key,
+ GThread *thread,
+ gpointer data,
+ GDestroyNotify notify);
+
+typedef struct _GStaticRecMutex GStaticRecMutex;
+struct _GStaticRecMutex
+{
+ GStaticMutex mutex;
+ unsigned int depth;
+ GSystemThread owner;
+};
+
+#define G_STATIC_REC_MUTEX_INIT { G_STATIC_MUTEX_INIT }
+void g_static_rec_mutex_lock (GStaticRecMutex *mutex);
+gboolean g_static_rec_mutex_trylock (GStaticRecMutex *mutex);
+void g_static_rec_mutex_unlock (GStaticRecMutex *mutex);
+void g_static_rec_mutex_lock_full (GStaticRecMutex *mutex,
+ guint depth);
+guint g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex);
+
+typedef struct _GStaticRWLock GStaticRWLock;
+struct _GStaticRWLock
+{
+ GStaticMutex mutex;
+ GCond *read_cond;
+ GCond *write_cond;
+ guint read_counter;
+ gboolean write;
+ guint want_to_write;
+};