diff options
author | Sebastian Wilhelmi <wilhelmi@ira.uka.de> | 1999-11-16 10:29:27 +0000 |
---|---|---|
committer | Sebastian Wilhelmi <wilhelmi@src.gnome.org> | 1999-11-16 10:29:27 +0000 |
commit | f0f028abd2df8255a68165c11d22e0433b600fdf (patch) | |
tree | 4dc5c76a2ce3a6afb4e52df148048a2af25bf30d /gthread | |
parent | b1d311d00cf8855c691efda45bc1f8194da5be1b (diff) | |
download | glib-f0f028abd2df8255a68165c11d22e0433b600fdf.tar.gz glib-f0f028abd2df8255a68165c11d22e0433b600fdf.tar.bz2 glib-f0f028abd2df8255a68165c11d22e0433b600fdf.zip |
Changed the prototype of thread_create and thread_self to return the
1999-11-16 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gthread-posix.c, gthread-solaris.c: Changed the prototype of
thread_create and thread_self to return the system thread into
provided memory instead of a return value. This is necessary, as
HPUX has a pthread_t, that is bigger than the biggest integral
type there. Made some more functions static.
* gthread-posix.c: Small fixes for DCE threads: Detaching has to
be done after thread creation for DCE.
Diffstat (limited to 'gthread')
-rw-r--r-- | gthread/ChangeLog | 11 | ||||
-rw-r--r-- | gthread/gthread-posix.c | 90 | ||||
-rw-r--r-- | gthread/gthread-solaris.c | 34 |
3 files changed, 74 insertions, 61 deletions
diff --git a/gthread/ChangeLog b/gthread/ChangeLog index 4956db34d..b0d99dac7 100644 --- a/gthread/ChangeLog +++ b/gthread/ChangeLog @@ -1,3 +1,14 @@ +1999-11-16 Sebastian Wilhelmi <wilhelmi@ira.uka.de> + + * gthread-posix.c, gthread-solaris.c: Changed the prototype of + thread_create and thread_self to return the system thread into + provided memory instead of a return value. This is necessary, as + HPUX has a pthread_t, that is bigger than the biggest integral + type there. Made some more functions static. + + * gthread-posix.c: Small fixes for DCE threads: Detaching has to + be done after thread creation for DCE. + 1999-06-21 Tor Lillqvist <tml@iki.fi> * gthread-posix.c: Guard pthread_attr_setscope call with test diff --git a/gthread/gthread-posix.c b/gthread/gthread-posix.c index 079f05b7c..b785a7119 100644 --- a/gthread/gthread-posix.c +++ b/gthread/gthread-posix.c @@ -38,19 +38,6 @@ #include <sys/time.h> #endif -#if GLIB_SIZEOF_PTHREAD_T == 2 -#define PTHREAD_T_CAST_INT gint16 -#elif GLIB_SIZEOF_PTHREAD_T == 4 -#define PTHREAD_T_CAST_INT gint32 -#elif GLIB_SIZEOF_PTHREAD_T == 8 && defined(G_HAVE_GINT64) -#define PTHREAD_T_CAST_INT gint64 -#else -# error This should not happen. Contact the GLib team. -#endif - -#define GPOINTER_TO_PTHREAD_T(x) ((pthread_t)(PTHREAD_T_CAST_INT)(x)) -#define PTHREAD_T_TO_GPOINTER(x) ((gpointer)(PTHREAD_T_CAST_INT)(x)) - #define posix_print_error( name, num ) \ g_error( "file %s: line %d (%s): error %s during %s", \ __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \ @@ -70,9 +57,9 @@ # define pthread_key_create(a, b) pthread_keycreate (a, b) # define pthread_attr_init(a) pthread_attr_create (a) # define pthread_attr_destroy(a) pthread_attr_delete (a) -# define pthread_create(a, b, c, d) pthread_create(a, &b, c, d) -# define mutexattr_default (&pthread_mutexattr_default) -# define condattr_default (&pthread_condattr_default) +# define pthread_create(a, b, c, d) pthread_create(a, *b, c, d) +# define mutexattr_default (pthread_mutexattr_default) +# define condattr_default (pthread_condattr_default) #else /* neither G_THREADS_IMPL_POSIX nor G_THREADS_IMPL_DCE are defined */ # error This should not happen. Contact the GLib team. #endif @@ -224,19 +211,18 @@ g_private_get_posix_impl (GPrivate * private_key) #endif } -gpointer +static void g_thread_create_posix_impl (GThreadFunc thread_func, gpointer arg, gulong stack_size, gboolean joinable, gboolean bound, - GThreadPriority priority) -{ - pthread_t thread; + GThreadPriority priority, + gpointer thread) +{ pthread_attr_t attr; - struct sched_param sched; - g_return_val_if_fail (thread_func, NULL); + g_return_if_fail (thread_func); posix_check_for_error (pthread_attr_init (&attr)); @@ -245,71 +231,83 @@ g_thread_create_posix_impl (GThreadFunc thread_func, posix_check_for_error (pthread_attr_setstacksize (&attr, stack_size)); #endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */ -#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING +#ifdef PTHREAD_SCOPE_SYSTEM if (bound) posix_check_for_error (pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM)); -#endif +#endif /* PTHREAD_SCOPE_SYSTEM */ - posix_check_for_error( pthread_attr_setdetachstate( &attr, - joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED ) ); +#ifdef G_THREADS_IMPL_POSIX + posix_check_for_error (pthread_attr_setdetachstate (&attr, + joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED)); +#endif /* G_THREADS_IMPL_POSIX */ #ifdef G_THREADS_IMPL_POSIX - posix_check_for_error (pthread_attr_getschedparam (&attr, &sched)); - sched.sched_priority = g_thread_map_priority (priority); - posix_check_for_error (pthread_attr_setschedparam (&attr, &sched)); + { + struct sched_param sched; + posix_check_for_error (pthread_attr_getschedparam (&attr, &sched)); + sched.sched_priority = g_thread_map_priority (priority); + posix_check_for_error (pthread_attr_setschedparam (&attr, &sched)); + } #else /* G_THREADS_IMPL_DCE */ posix_check_for_error - (pthread_attr_setprio (&attr, g_thread_map_priority (priority)); -#endif + (pthread_attr_setprio (&attr, g_thread_map_priority (priority))); +#endif /* G_THREADS_IMPL_DCE */ - posix_check_for_error( pthread_create (&thread, &attr, + posix_check_for_error (pthread_create (thread, &attr, (void* (*)(void*))thread_func, - arg) ); + arg)); - posix_check_for_error( pthread_attr_destroy (&attr) ); + posix_check_for_error (pthread_attr_destroy (&attr)); - return PTHREAD_T_TO_GPOINTER (thread); +#ifdef G_THREADS_IMPL_DCE + if (!joinable) + posix_check_for_error (pthread_detach (thread)); +#endif /* G_THREADS_IMPL_DCE */ } -void +static void g_thread_yield_posix_impl (void) { POSIX_YIELD_FUNC; } -void +static void g_thread_join_posix_impl (gpointer thread) { gpointer ignore; - posix_check_for_error (pthread_join (GPOINTER_TO_PTHREAD_T (thread), + posix_check_for_error (pthread_join (*(pthread_t*)thread, &ignore)); } -void +static void g_thread_exit_posix_impl (void) { pthread_exit (NULL); } -void +static void g_thread_set_priority_posix_impl (gpointer thread, GThreadPriority priority) { +#ifdef G_THREADS_IMPL_POSIX struct sched_param sched; int policy; - -#ifdef G_THREADS_IMPL_POSIX - posix_check_for_error (pthread_getschedparam (GPOINTER_TO_PTHREAD_T (thread), + posix_check_for_error (pthread_getschedparam (*(pthread_t*)thread, &policy, &sched)); sched.sched_priority = g_thread_map_priority (priority); - posix_check_for_error (pthread_setschedparam (GPOINTER_TO_PTHREAD_T (thread), + posix_check_for_error (pthread_setschedparam (*(pthread_t*)thread, policy, &sched)); #else /* G_THREADS_IMPL_DCE */ - posix_check_for_error (pthread_setprio (GPOINTER_TO_PTHREAD_T (thread), + posix_check_for_error (pthread_setprio (*(pthread_t*)thread, g_thread_map_priority (priority))); #endif } +static void +g_thread_self_posix_impl (gpointer thread) +{ + *(pthread_t*)thread = pthread_self(); +} static GThreadFunctions g_thread_functions_for_glib_use_default = { @@ -332,5 +330,5 @@ static GThreadFunctions g_thread_functions_for_glib_use_default = g_thread_join_posix_impl, g_thread_exit_posix_impl, g_thread_set_priority_posix_impl, - (gpointer (*)())pthread_self + g_thread_self_posix_impl }; diff --git a/gthread/gthread-solaris.c b/gthread/gthread-solaris.c index 1c189b2dd..43a38ed53 100644 --- a/gthread/gthread-solaris.c +++ b/gthread/gthread-solaris.c @@ -173,54 +173,58 @@ g_private_get_solaris_impl (GPrivate * private_key) return result; } -void +static void g_thread_set_priority_solaris_impl (gpointer thread, GThreadPriority priority) { - solaris_check_for_error (thr_setprio (GPOINTER_TO_INT (thread), + solaris_check_for_error (thr_setprio (*(thread_t*)thread, g_thread_map_priority (priority))); } -gpointer +static void g_thread_create_solaris_impl (GThreadFunc thread_func, gpointer arg, gulong stack_size, gboolean joinable, gboolean bound, - GThreadPriority priority) + GThreadPriority priority, + gpointer thread) { - thread_t thread; long flags = (bound ? THR_BOUND : 0) | (joinable ? 0: THR_DETACHED); - g_return_val_if_fail (thread_func, NULL); + g_return_if_fail (thread_func); solaris_check_for_error (thr_create (NULL, stack_size, (void* (*)(void*))thread_func, - arg, flags, &thread)); + arg, flags, thread)); - g_thread_set_priority_solaris_impl (GINT_TO_POINTER (thread), priority); - - return GINT_TO_POINTER (thread); + g_thread_set_priority_solaris_impl (thread, priority); } -void +static void g_thread_yield_solaris_impl (void) { thr_yield (); } -void +static void g_thread_join_solaris_impl (gpointer thread) { gpointer ignore; - solaris_check_for_error (thr_join (GPOINTER_TO_INT (thread), NULL, &ignore)); + solaris_check_for_error (thr_join (*(thread_t*)thread, NULL, &ignore)); } -void +static void g_thread_exit_solaris_impl (void) { thr_exit (NULL); } +static void +g_thread_self_solaris_impl (gpointer thread) +{ + *(thread_t*)thread = thr_self(); +} + static GThreadFunctions g_thread_functions_for_glib_use_default = { g_mutex_new_solaris_impl, @@ -242,5 +246,5 @@ 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, - (gpointer (*)())thr_self + g_thread_self_solaris_impl }; |