Use encoding names which may work better on Solaris. (#340434, Alessandro
[platform/upstream/glib.git] / gthread / gthread-solaris.c
index 99e5ee9..4f21798 100644 (file)
@@ -31,6 +31,8 @@
  * 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 *
@@ -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
@@ -184,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
@@ -201,8 +207,11 @@ g_thread_create_solaris_impl (GThreadFunc thread_func,
   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);
   
   ret = thr_create (NULL, stack_size, (void* (*)(void*))thread_func,
                    arg, flags, thread);
@@ -265,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 */
 };