* MT safe
*/
+#include <config.h>
+
#include <thread.h>
#include <errno.h>
#include <stdlib.h>
if( error ) { solaris_print_error( what, error ); } \
}G_STMT_END
-gulong g_thread_min_stack_size = 0;
+static gulong g_thread_min_stack_size = 0;
+
+#define G_MUTEX_SIZE (sizeof (mutex_t))
+
+#define PRIORITY_LOW_VALUE 0
+#define PRIORITY_NORMAL_VALUE 50
+#define PRIORITY_URGENT_VALUE 127
#define HAVE_G_THREAD_IMPL_INIT
static void
g_thread_impl_init()
{
- g_thread_min_priority = 0;
- g_thread_max_priority = 127;
-#ifdef _SC_THREAD_STACK_MIN
- g_thread_min_stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN), 0);
-#endif /* _SC_THREAD_STACK_MIN */
+ g_thread_min_stack_size = thr_min_stack();
+ /* The default priority on Solaris is 0. Set it to something sane */
+ solaris_check_for_error (thr_setprio (thr_self (), PRIORITY_NORMAL_VALUE));
}
static GMutex *
g_mutex_free_solaris_impl (GMutex * mutex)
{
solaris_check_for_error (mutex_destroy ((mutex_t *) mutex));
- free (mutex);
+ g_free (mutex);
}
/* NOTE: the functions g_mutex_lock and g_mutex_unlock may not use
without error check then!!!!, we might want to change this
therfore. */
-#define G_MICROSEC 1000000
-#define G_NANOSEC 1000000000
+#define G_NSEC_PER_SEC 1000000000
static gboolean
g_cond_timed_wait_solaris_impl (GCond * cond,
}
end_time.tv_sec = abs_time->tv_sec;
- end_time.tv_nsec = abs_time->tv_usec * (G_NANOSEC / G_MICROSEC);
- g_assert (end_time.tv_nsec < G_NANOSEC);
+ end_time.tv_nsec = abs_time->tv_usec * (G_NSEC_PER_SEC / G_USEC_PER_SEC);
+ g_assert (end_time.tv_nsec < G_NSEC_PER_SEC);
result = cond_timedwait ((cond_t *) cond, (mutex_t *) entered_mutex,
&end_time);
timed_out = (result == ETIME);
g_thread_set_priority_solaris_impl (gpointer thread, GThreadPriority priority)
{
solaris_check_for_error (thr_setprio (*(thread_t*)thread,
- g_thread_map_priority (priority)));
+ g_thread_priority_map [priority]));
}
static void
gboolean joinable,
gboolean bound,
GThreadPriority priority,
- gpointer thread)
+ gpointer thread,
+ GError **error)
{
long flags = (bound ? THR_BOUND : 0) | (joinable ? 0: THR_DETACHED);
+ gint ret;
g_return_if_fail (thread_func);
+ g_return_if_fail (priority >= G_THREAD_PRIORITY_LOW);
+ g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);
- stack_size = MAX (g_thread_min_stack_size, stack_size);
+ if (stack_size)
+ stack_size = MAX (g_thread_min_stack_size, stack_size);
- solaris_check_for_error (thr_create (NULL, stack_size,
- (void* (*)(void*))thread_func,
- arg, flags, thread));
+ ret = thr_create (NULL, stack_size, (void* (*)(void*))thread_func,
+ arg, flags, thread);
+
+ if (ret == EAGAIN)
+ {
+ g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,
+ "Error creating thread: %s", g_strerror (ret));
+ return;
+ }
+ solaris_check_for_error (ret);
+
g_thread_set_priority_solaris_impl (thread, priority);
}
g_thread_join_solaris_impl,
g_thread_exit_solaris_impl,
g_thread_set_priority_solaris_impl,
- g_thread_self_solaris_impl
+ g_thread_self_solaris_impl,
+ NULL /* no equal function necessary on Solaris */
};