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/.
42 #define solaris_print_error( name, num ) \
43 g_error( "file %s: line %d (%s): error %s during %s", \
44 __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
45 g_strerror((num)), #name )
47 #define solaris_check_for_error( what ) G_STMT_START{ \
49 if( error ) { solaris_print_error( what, error ); } \
52 gulong g_thread_min_stack_size = 0;
54 #define HAVE_G_THREAD_IMPL_INIT
58 g_thread_min_priority = 0;
59 g_thread_max_priority = 127;
60 #ifdef _SC_THREAD_STACK_MIN
61 g_thread_min_stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN), 0);
62 #endif /* _SC_THREAD_STACK_MIN */
66 g_mutex_new_solaris_impl (void)
68 GMutex *result = (GMutex *) g_new (mutex_t, 1);
69 solaris_check_for_error (mutex_init ((mutex_t *) result, USYNC_PROCESS, 0));
74 g_mutex_free_solaris_impl (GMutex * mutex)
76 solaris_check_for_error (mutex_destroy ((mutex_t *) mutex));
80 /* NOTE: the functions g_mutex_lock and g_mutex_unlock may not use
81 functions from gmem.c and gmessages.c; */
83 /* mutex_lock, mutex_unlock can be taken directly, as
84 signature and semantic are right, but without error check then!!!!,
85 we might want to change this therefore. */
88 g_mutex_trylock_solaris_impl (GMutex * mutex)
91 result = mutex_trylock ((mutex_t *) mutex);
94 solaris_check_for_error (result);
99 g_cond_new_solaris_impl ()
101 GCond *result = (GCond *) g_new (cond_t, 1);
102 solaris_check_for_error (cond_init ((cond_t *) result, USYNC_THREAD, 0));
106 /* cond_signal, cond_broadcast and cond_wait
107 can be taken directly, as signature and semantic are right, but
108 without error check then!!!!, we might want to change this
111 #define G_MICROSEC 1000000
112 #define G_NANOSEC 1000000000
115 g_cond_timed_wait_solaris_impl (GCond * cond,
116 GMutex * entered_mutex,
120 timestruc_t end_time;
123 g_return_val_if_fail (cond != NULL, FALSE);
124 g_return_val_if_fail (entered_mutex != NULL, FALSE);
128 g_cond_wait (cond, entered_mutex);
132 end_time.tv_sec = abs_time->tv_sec;
133 end_time.tv_nsec = abs_time->tv_usec * (G_NANOSEC / G_MICROSEC);
134 g_assert (end_time.tv_nsec < G_NANOSEC);
135 result = cond_timedwait ((cond_t *) cond, (mutex_t *) entered_mutex,
137 timed_out = (result == ETIME);
139 solaris_check_for_error (result);
144 g_cond_free_solaris_impl (GCond * cond)
146 solaris_check_for_error (cond_destroy ((cond_t *) cond));
151 g_private_new_solaris_impl (GDestroyNotify destructor)
153 GPrivate *result = (GPrivate *) g_new (thread_key_t,1);
154 solaris_check_for_error (thr_keycreate ((thread_key_t *) result,
159 /* NOTE: the functions g_private_get and g_private_set may not use
160 functions from gmem.c and gmessages.c */
163 g_private_set_solaris_impl (GPrivate * private_key, gpointer value)
168 thr_setspecific (*(thread_key_t *) private_key, value);
172 g_private_get_solaris_impl (GPrivate * private_key)
179 thr_getspecific (*(thread_key_t *) private_key, &result);
185 g_thread_set_priority_solaris_impl (gpointer thread, GThreadPriority priority)
187 solaris_check_for_error (thr_setprio (*(thread_t*)thread,
188 g_thread_map_priority (priority)));
192 g_thread_create_solaris_impl (GThreadFunc thread_func,
197 GThreadPriority priority,
200 long flags = (bound ? THR_BOUND : 0) | (joinable ? 0: THR_DETACHED);
202 g_return_if_fail (thread_func);
204 stack_size = MAX (g_thread_min_stack_size, stack_size);
206 solaris_check_for_error (thr_create (NULL, stack_size,
207 (void* (*)(void*))thread_func,
208 arg, flags, thread));
210 g_thread_set_priority_solaris_impl (thread, priority);
214 g_thread_yield_solaris_impl (void)
220 g_thread_join_solaris_impl (gpointer thread)
223 solaris_check_for_error (thr_join (*(thread_t*)thread, NULL, &ignore));
227 g_thread_exit_solaris_impl (void)
233 g_thread_self_solaris_impl (gpointer thread)
235 *(thread_t*)thread = thr_self();
238 static GThreadFunctions g_thread_functions_for_glib_use_default =
240 g_mutex_new_solaris_impl,
241 (void (*)(GMutex *)) mutex_lock,
242 g_mutex_trylock_solaris_impl,
243 (void (*)(GMutex *)) mutex_unlock,
244 g_mutex_free_solaris_impl,
245 g_cond_new_solaris_impl,
246 (void (*)(GCond *)) cond_signal,
247 (void (*)(GCond *)) cond_broadcast,
248 (void (*)(GCond *, GMutex *)) cond_wait,
249 g_cond_timed_wait_solaris_impl,
250 g_cond_free_solaris_impl,
251 g_private_new_solaris_impl,
252 g_private_get_solaris_impl,
253 g_private_set_solaris_impl,
254 g_thread_create_solaris_impl,
255 g_thread_yield_solaris_impl,
256 g_thread_join_solaris_impl,
257 g_thread_exit_solaris_impl,
258 g_thread_set_priority_solaris_impl,
259 g_thread_self_solaris_impl