/*
 * This file is part of roccat-tools.
 *
 * roccat-tools is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * roccat-tools 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with roccat-tools. If not, see <http://www.gnu.org/licenses/>.
 */

#include "g_thread_roccat_helper.h"

GThread *g_roccat_thread_try_new(gchar const *name, GThreadFunc func, gpointer data, GError **error) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	return g_thread_try_new(name, func, data, error);
#else
	return g_thread_create(func, data, TRUE, error);
#endif
}

void g_roccat_mutex_init(GRoccatMutex *mutex) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_mutex_init(mutex);
#else
	*mutex = g_mutex_new();
#endif
}

void g_roccat_mutex_clear(GRoccatMutex *mutex) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_mutex_clear(mutex);
#else
	g_mutex_free(*mutex);
#endif
}

void g_roccat_mutex_lock(GRoccatMutex *mutex) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_mutex_lock(mutex);
#else
	g_mutex_lock(*mutex);
#endif
}

void g_roccat_mutex_unlock(GRoccatMutex *mutex) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_mutex_unlock(mutex);
#else
	g_mutex_unlock(*mutex);
#endif
}

void g_roccat_cond_init(GRoccatCond *cond) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_cond_init(cond);
#else
	*cond = g_cond_new();
#endif
}

void g_roccat_cond_clear(GRoccatCond *cond) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_cond_clear(cond);
#else
	g_cond_free(*cond);
#endif
}

void g_roccat_cond_wait(GRoccatCond *cond, GRoccatMutex *mutex) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_cond_wait(cond, mutex);
#else
	g_cond_wait(*cond, *mutex);
#endif
}

void g_roccat_cond_signal(GRoccatCond *cond) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_cond_signal(cond);
#else
	g_cond_signal(*cond);
#endif
}

void g_roccat_rec_mutex_init(GRoccatRecMutex *mutex) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_rec_mutex_init(mutex);
#else
	g_static_rec_mutex_init(mutex);
#endif
}

void g_roccat_rec_mutex_clear(GRoccatRecMutex *mutex) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_rec_mutex_clear(mutex);
#else
	g_static_rec_mutex_free(mutex);
#endif
}

void g_roccat_rec_mutex_lock(GRoccatRecMutex *mutex) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_rec_mutex_lock(mutex);
#else
	g_static_rec_mutex_lock(mutex);
#endif
}

void g_roccat_rec_mutex_unlock(GRoccatRecMutex *mutex) {
#if (GLIB_CHECK_VERSION(2, 32, 0))
	g_rec_mutex_unlock(mutex);
#else
	g_static_rec_mutex_unlock(mutex);
#endif
}
