Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / glib / gthread / gthread-solaris.c
blob4d9c3758c11cf83f1a684adffb209cebe880f5be
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * gthread.c: solaris thread system implementation
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 #include <thread.h>
35 #include <errno.h>
36 #include <stdlib.h>
37 #include <stdio.h>
39 #define solaris_print_error( name, num ) \
40 g_error( "file %s: line %d (%s): error %s during %s", \
41 __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
42 g_strerror((num)), #name )
44 #define solaris_check_for_error( what ) G_STMT_START{ \
45 int error = (what); \
46 if( error ) { solaris_print_error( what, error ); } \
47 }G_STMT_END
49 static GMutex *
50 g_mutex_new_solaris_impl (void)
52 GMutex *result = (GMutex *) g_new (mutex_t, 1);
53 solaris_check_for_error (mutex_init ((mutex_t *) result, USYNC_PROCESS, 0));
54 return result;
57 static void
58 g_mutex_free_solaris_impl (GMutex * mutex)
60 solaris_check_for_error (mutex_destroy ((mutex_t *) mutex));
61 free (mutex);
64 /* NOTE: the functions g_mutex_lock and g_mutex_unlock may not use
65 functions from gmem.c and gmessages.c; */
67 /* mutex_lock, mutex_unlock can be taken directly, as
68 signature and semantic are right, but without error check then!!!!,
69 we might want to change this therefore. */
71 static gboolean
72 g_mutex_trylock_solaris_impl (GMutex * mutex)
74 int result;
75 result = mutex_trylock ((mutex_t *) mutex);
76 if (result == EBUSY)
77 return FALSE;
78 solaris_check_for_error (result);
79 return TRUE;
82 static GCond *
83 g_cond_new_solaris_impl ()
85 GCond *result = (GCond *) g_new (cond_t, 1);
86 solaris_check_for_error (cond_init ((cond_t *) result, USYNC_THREAD, 0));
87 return result;
90 /* cond_signal, cond_broadcast and cond_wait
91 can be taken directly, as signature and semantic are right, but
92 without error check then!!!!, we might want to change this
93 therfore. */
95 #define G_MICROSEC 1000000
96 #define G_NANOSEC 1000000000
98 static gboolean
99 g_cond_timed_wait_solaris_impl (GCond * cond,
100 GMutex * entered_mutex,
101 GTimeVal * abs_time)
103 int result;
104 timestruc_t end_time;
105 gboolean timed_out;
107 g_return_val_if_fail (cond != NULL, FALSE);
108 g_return_val_if_fail (entered_mutex != NULL, FALSE);
110 if (!abs_time)
112 g_cond_wait (cond, entered_mutex);
113 return TRUE;
116 end_time.tv_sec = abs_time->tv_sec;
117 end_time.tv_nsec = abs_time->tv_usec * (G_NANOSEC / G_MICROSEC);
118 g_assert (end_time.tv_nsec < G_NANOSEC);
119 result = cond_timedwait ((cond_t *) cond, (mutex_t *) entered_mutex,
120 &end_time);
121 timed_out = (result == ETIME);
122 if (!timed_out)
123 solaris_check_for_error (result);
124 return !timed_out;
127 static void
128 g_cond_free_solaris_impl (GCond * cond)
130 solaris_check_for_error (cond_destroy ((cond_t *) cond));
131 g_free (cond);
134 static GPrivate *
135 g_private_new_solaris_impl (GDestroyNotify destructor)
137 GPrivate *result = (GPrivate *) g_new (thread_key_t,1);
138 solaris_check_for_error (thr_keycreate ((thread_key_t *) result,
139 destructor));
140 return result;
143 /* NOTE: the functions g_private_get and g_private_set may not use
144 functions from gmem.c and gmessages.c */
146 static void
147 g_private_set_solaris_impl (GPrivate * private_key, gpointer value)
149 if (!private_key)
150 return;
152 thr_setspecific (*(thread_key_t *) private_key, value);
155 static gpointer
156 g_private_get_solaris_impl (GPrivate * private_key)
158 gpointer result;
160 if (!private_key)
161 return NULL;
163 thr_getspecific (*(thread_key_t *) private_key, &result);
165 return result;
168 static GThreadFunctions g_thread_functions_for_glib_use_default =
170 g_mutex_new_solaris_impl,
171 (void (*)(GMutex *)) mutex_lock,
172 g_mutex_trylock_solaris_impl,
173 (void (*)(GMutex *)) mutex_unlock,
174 g_mutex_free_solaris_impl,
175 g_cond_new_solaris_impl,
176 (void (*)(GCond *)) cond_signal,
177 (void (*)(GCond *)) cond_broadcast,
178 (void (*)(GCond *, GMutex *)) cond_wait,
179 g_cond_timed_wait_solaris_impl,
180 g_cond_free_solaris_impl,
181 g_private_new_solaris_impl,
182 g_private_get_solaris_impl,
183 g_private_set_solaris_impl