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.
This commit is contained in:
Sebastian Wilhelmi 1999-11-16 10:29:27 +00:00 committed by Sebastian Wilhelmi
parent b1d311d00c
commit f0f028abd2
3 changed files with 74 additions and 61 deletions

View File

@ -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> 1999-06-21 Tor Lillqvist <tml@iki.fi>
* gthread-posix.c: Guard pthread_attr_setscope call with test * gthread-posix.c: Guard pthread_attr_setscope call with test

View File

@ -38,19 +38,6 @@
#include <sys/time.h> #include <sys/time.h>
#endif #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 ) \ #define posix_print_error( name, num ) \
g_error( "file %s: line %d (%s): error %s during %s", \ g_error( "file %s: line %d (%s): error %s during %s", \
__FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \ __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
@ -70,9 +57,9 @@
# define pthread_key_create(a, b) pthread_keycreate (a, b) # define pthread_key_create(a, b) pthread_keycreate (a, b)
# define pthread_attr_init(a) pthread_attr_create (a) # define pthread_attr_init(a) pthread_attr_create (a)
# define pthread_attr_destroy(a) pthread_attr_delete (a) # define pthread_attr_destroy(a) pthread_attr_delete (a)
# define pthread_create(a, b, c, d) pthread_create(a, &b, c, d) # define pthread_create(a, b, c, d) pthread_create(a, *b, c, d)
# define mutexattr_default (&pthread_mutexattr_default) # define mutexattr_default (pthread_mutexattr_default)
# define condattr_default (&pthread_condattr_default) # define condattr_default (pthread_condattr_default)
#else /* neither G_THREADS_IMPL_POSIX nor G_THREADS_IMPL_DCE are defined */ #else /* neither G_THREADS_IMPL_POSIX nor G_THREADS_IMPL_DCE are defined */
# error This should not happen. Contact the GLib team. # error This should not happen. Contact the GLib team.
#endif #endif
@ -224,19 +211,18 @@ g_private_get_posix_impl (GPrivate * private_key)
#endif #endif
} }
gpointer static void
g_thread_create_posix_impl (GThreadFunc thread_func, g_thread_create_posix_impl (GThreadFunc thread_func,
gpointer arg, gpointer arg,
gulong stack_size, gulong stack_size,
gboolean joinable, gboolean joinable,
gboolean bound, gboolean bound,
GThreadPriority priority) GThreadPriority priority,
{ gpointer thread)
pthread_t thread; {
pthread_attr_t attr; 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)); 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)); posix_check_for_error (pthread_attr_setstacksize (&attr, stack_size));
#endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */ #endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING #ifdef PTHREAD_SCOPE_SYSTEM
if (bound) if (bound)
posix_check_for_error (pthread_attr_setscope (&attr, posix_check_for_error (pthread_attr_setscope (&attr,
PTHREAD_SCOPE_SYSTEM)); PTHREAD_SCOPE_SYSTEM));
#endif #endif /* PTHREAD_SCOPE_SYSTEM */
posix_check_for_error( pthread_attr_setdetachstate( &attr, #ifdef G_THREADS_IMPL_POSIX
joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED ) ); 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 #ifdef G_THREADS_IMPL_POSIX
posix_check_for_error (pthread_attr_getschedparam (&attr, &sched)); {
sched.sched_priority = g_thread_map_priority (priority); struct sched_param sched;
posix_check_for_error (pthread_attr_setschedparam (&attr, &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 */ #else /* G_THREADS_IMPL_DCE */
posix_check_for_error posix_check_for_error
(pthread_attr_setprio (&attr, g_thread_map_priority (priority)); (pthread_attr_setprio (&attr, g_thread_map_priority (priority)));
#endif #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, (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) g_thread_yield_posix_impl (void)
{ {
POSIX_YIELD_FUNC; POSIX_YIELD_FUNC;
} }
void static void
g_thread_join_posix_impl (gpointer thread) g_thread_join_posix_impl (gpointer thread)
{ {
gpointer ignore; gpointer ignore;
posix_check_for_error (pthread_join (GPOINTER_TO_PTHREAD_T (thread), posix_check_for_error (pthread_join (*(pthread_t*)thread,
&ignore)); &ignore));
} }
void static void
g_thread_exit_posix_impl (void) g_thread_exit_posix_impl (void)
{ {
pthread_exit (NULL); pthread_exit (NULL);
} }
void static void
g_thread_set_priority_posix_impl (gpointer thread, GThreadPriority priority) g_thread_set_priority_posix_impl (gpointer thread, GThreadPriority priority)
{ {
#ifdef G_THREADS_IMPL_POSIX
struct sched_param sched; struct sched_param sched;
int policy; int policy;
posix_check_for_error (pthread_getschedparam (*(pthread_t*)thread,
#ifdef G_THREADS_IMPL_POSIX
posix_check_for_error (pthread_getschedparam (GPOINTER_TO_PTHREAD_T (thread),
&policy, &sched)); &policy, &sched));
sched.sched_priority = g_thread_map_priority (priority); 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)); policy, &sched));
#else /* G_THREADS_IMPL_DCE */ #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))); g_thread_map_priority (priority)));
#endif #endif
} }
static void
g_thread_self_posix_impl (gpointer thread)
{
*(pthread_t*)thread = pthread_self();
}
static GThreadFunctions g_thread_functions_for_glib_use_default = 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_join_posix_impl,
g_thread_exit_posix_impl, g_thread_exit_posix_impl,
g_thread_set_priority_posix_impl, g_thread_set_priority_posix_impl,
(gpointer (*)())pthread_self g_thread_self_posix_impl
}; };

View File

@ -173,54 +173,58 @@ g_private_get_solaris_impl (GPrivate * private_key)
return result; return result;
} }
void static void
g_thread_set_priority_solaris_impl (gpointer thread, GThreadPriority priority) 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))); g_thread_map_priority (priority)));
} }
gpointer static void
g_thread_create_solaris_impl (GThreadFunc thread_func, g_thread_create_solaris_impl (GThreadFunc thread_func,
gpointer arg, gpointer arg,
gulong stack_size, gulong stack_size,
gboolean joinable, gboolean joinable,
gboolean bound, gboolean bound,
GThreadPriority priority) GThreadPriority priority,
gpointer thread)
{ {
thread_t thread;
long flags = (bound ? THR_BOUND : 0) | (joinable ? 0: THR_DETACHED); 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, solaris_check_for_error (thr_create (NULL, stack_size,
(void* (*)(void*))thread_func, (void* (*)(void*))thread_func,
arg, flags, &thread)); arg, flags, thread));
g_thread_set_priority_solaris_impl (GINT_TO_POINTER (thread), priority); g_thread_set_priority_solaris_impl (thread, priority);
return GINT_TO_POINTER (thread);
} }
void static void
g_thread_yield_solaris_impl (void) g_thread_yield_solaris_impl (void)
{ {
thr_yield (); thr_yield ();
} }
void static void
g_thread_join_solaris_impl (gpointer thread) g_thread_join_solaris_impl (gpointer thread)
{ {
gpointer ignore; 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) g_thread_exit_solaris_impl (void)
{ {
thr_exit (NULL); 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 = static GThreadFunctions g_thread_functions_for_glib_use_default =
{ {
g_mutex_new_solaris_impl, 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_join_solaris_impl,
g_thread_exit_solaris_impl, g_thread_exit_solaris_impl,
g_thread_set_priority_solaris_impl, g_thread_set_priority_solaris_impl,
(gpointer (*)())thr_self g_thread_self_solaris_impl
}; };