X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gthread%2Fgthread-solaris.c;h=4f2179899d1a86f5f83055aee776067b66ad8ab9;hb=eb9ff053201f717f0e149e13b6de1018d440270a;hp=c8d4302b9320ebb903133f9f2e656658e361e612;hpb=c9bd7542e1a28ba9de60048361c0a97d251833e7;p=platform%2Fupstream%2Fglib.git diff --git a/gthread/gthread-solaris.c b/gthread/gthread-solaris.c index c8d4302..4f21798 100644 --- a/gthread/gthread-solaris.c +++ b/gthread/gthread-solaris.c @@ -31,6 +31,8 @@ * MT safe */ +#include + #include #include #include @@ -49,17 +51,21 @@ 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 * @@ -74,7 +80,7 @@ static void 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 @@ -108,8 +114,7 @@ g_cond_new_solaris_impl () 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, @@ -130,8 +135,8 @@ 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); @@ -185,7 +190,7 @@ static void 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 @@ -195,18 +200,31 @@ g_thread_create_solaris_impl (GThreadFunc thread_func, 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); } @@ -256,5 +274,6 @@ static GThreadFunctions g_thread_functions_for_glib_use_default = 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 */ };