glib/gthread/gthread.c
Sebastian Wilhelmi a5ae4f8f99 Made the thread related code follow GNU coding standard.
1998-12-09  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

	* Made the thread related code follow GNU coding standard.

	* Made a comment (HOLDS:) above each function, that expects the
	given locks to be held.

	* Changed try_lock to trylock throughout.

	* glib.c: Eventually removed the #if 0'ed code for old GStaticMutex.

	* glib.c: Corrected g_trylock macro for G_DEBUG_LOCKS.

	* gmain.c (g_main_poll_add_unlocked): first take a new poll record
	form the poll_free_list.

	* gmem.c, gstrfuncs.c, gutils.c: Made it MT safe.

	* gthraed/*.c: Added copyright headers.

	* gthread/gthread-solaris.c: do not use g_log for errors, as g_log
	uses these module and endless recursions might happen, just use a
	plain fprintf(stderr,...).

	* gthread/gthread.c (g_thread_try_init): Call g_mutex_init().

	* gthread/testgthread.c: updated test program.
1998-12-09 14:55:11 +00:00

94 lines
2.5 KiB
C

/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* gthread.c: thread related functions
* Copyright 1998 Sebastian Wilhelmi; University of Karlsruhe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* MT safe
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <glib.h>
static const char *g_log_domain_gthread = "GThread";
static gboolean thread_system_already_initialized = FALSE;
#include G_THREAD_SOURCE
void g_mutex_init();
gboolean
g_thread_try_init(GThreadFunctions* init)
{
if (thread_system_already_initialized)
return FALSE;
thread_system_already_initialized = TRUE;
if (init == NULL)
{
g_thread_use_default_impl = TRUE;
init = &g_thread_functions_for_glib_use_default;
}
g_thread_functions_for_glib_use = *init;
g_thread_supported =
init->mutex_new &&
init->mutex_lock &&
init->mutex_trylock &&
init->mutex_unlock &&
init->mutex_free &&
init->cond_new &&
init->cond_signal &&
init->cond_broadcast &&
init->cond_wait &&
init->cond_timed_wait &&
init->cond_free &&
init->private_new &&
init->private_get &&
init->private_get;
/* if somebody is calling g_thread_init(), it means that he wants to
have thread support, so check this */
if (!g_thread_supported)
g_error( "Mutex functions missing." );
/* now call the thread initialization functions of the different
glib modules. BTW: order does matter, g_mutex_init MUST be first */
g_mutex_init();
return TRUE;
}
void
g_thread_init(GThreadFunctions* init)
{
/* Make sure, this function is only called once. */
if (!g_thread_try_init (init))
g_error( "the glib thread system may only be initialized once." );
}