Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / glib / gthread / gthread.c
blobf7d76bed88462f9113c12333d22427aa2a333148
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * gthread.c: thread related functions
5 * Copyright 1998 Sebastian Wilhelmi; University of Karlsruhe
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Modified by the GLib Team and others 1997-1999. See the AUTHORS
25 * file for a list of people on the GLib Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GLib at ftp://ftp.gtk.org/pub/gtk/.
30 /*
31 * MT safe
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
38 #include <glib.h>
40 static gboolean thread_system_already_initialized = FALSE;
42 #include G_THREAD_SOURCE
44 void g_mutex_init (void);
45 void g_mem_init (void);
46 void g_messages_init (void);
48 void
49 g_thread_init (GThreadFunctions* init)
51 gboolean supported;
53 #ifndef G_THREADS_ENABLED
54 g_error ("GLib thread support is disabled.");
55 #endif /* !G_THREADS_ENABLED */
57 if (thread_system_already_initialized)
58 g_error ("GThread system may only be initialized once.");
60 thread_system_already_initialized = TRUE;
62 if (init == NULL)
63 init = &g_thread_functions_for_glib_use_default;
64 else
65 g_thread_use_default_impl = FALSE;
67 g_thread_functions_for_glib_use = *init;
69 /* It is important, that g_threads_got_initialized is not set before the
70 * thread initialization functions of the different modules are called
73 supported = (init->mutex_new &&
74 init->mutex_lock &&
75 init->mutex_trylock &&
76 init->mutex_unlock &&
77 init->mutex_free &&
78 init->cond_new &&
79 init->cond_signal &&
80 init->cond_broadcast &&
81 init->cond_wait &&
82 init->cond_timed_wait &&
83 init->cond_free &&
84 init->private_new &&
85 init->private_get &&
86 init->private_get);
88 /* if somebody is calling g_thread_init (), it means that he wants to
89 * have thread support, so check this
91 if (!supported)
93 if (g_thread_use_default_impl)
94 g_error ("Threads are not supported on this platform.");
95 else
96 g_error ("The supplied thread function vector is invalid.");
99 /* now call the thread initialization functions of the different
100 * glib modules. order does matter, g_mutex_init MUST come first.
102 g_mutex_init ();
103 g_mem_init ();
104 g_messages_init ();
106 /* now we can set g_threads_got_initialized and thus enable
107 * all the thread functions
109 g_threads_got_initialized = TRUE;