From: Sebastian Wilhelmi Date: Thu, 15 Feb 2001 16:43:02 +0000 (+0000) Subject: Reverted the changes necessary to enlarge the system thread for X-Git-Tag: GLIB_1_3_3~113 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=efb2e89e07fc6bf0c1ac71e7750e99bc8f3f6119;p=platform%2Fupstream%2Fglib.git Reverted the changes necessary to enlarge the system thread for 2001-02-15 Sebastian Wilhelmi * acconfig.h, configure.in: Reverted the changes necessary to enlarge the system thread for G_THREAD_USE_PID_SURROGATE. * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c instead of gthread/gthread-posix.c. While the latter has the advantage, that it is conceptually cleaner, it makes g_thread_self_posix_impl _very_ slow and that hurts GStaticRecMutex and other things. So the new version is less clean, but faster. * gthread-posix.c: Removed the G_THREAD_USE_PID_SURROGATE implementation, which is now in gthread.c. --- diff --git a/ChangeLog b/ChangeLog index 0e9bc0d..d36fa0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2001-02-15 Sebastian Wilhelmi + + * acconfig.h, configure.in: Reverted the changes necessary to + enlarge the system thread for G_THREAD_USE_PID_SURROGATE. + + * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c + instead of gthread/gthread-posix.c. While the latter has the + advantage, that it is conceptually cleaner, it makes + g_thread_self_posix_impl _very_ slow and that hurts + GStaticRecMutex and other things. So the new version is less + clean, but faster. + 2001-02-09 Havoc Pennington * gconvert.c (g_convert): don't overwrite errors diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 0e9bc0d..d36fa0c 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,15 @@ +2001-02-15 Sebastian Wilhelmi + + * acconfig.h, configure.in: Reverted the changes necessary to + enlarge the system thread for G_THREAD_USE_PID_SURROGATE. + + * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c + instead of gthread/gthread-posix.c. While the latter has the + advantage, that it is conceptually cleaner, it makes + g_thread_self_posix_impl _very_ slow and that hurts + GStaticRecMutex and other things. So the new version is less + clean, but faster. + 2001-02-09 Havoc Pennington * gconvert.c (g_convert): don't overwrite errors diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 0e9bc0d..d36fa0c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +2001-02-15 Sebastian Wilhelmi + + * acconfig.h, configure.in: Reverted the changes necessary to + enlarge the system thread for G_THREAD_USE_PID_SURROGATE. + + * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c + instead of gthread/gthread-posix.c. While the latter has the + advantage, that it is conceptually cleaner, it makes + g_thread_self_posix_impl _very_ slow and that hurts + GStaticRecMutex and other things. So the new version is less + clean, but faster. + 2001-02-09 Havoc Pennington * gconvert.c (g_convert): don't overwrite errors diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 0e9bc0d..d36fa0c 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,15 @@ +2001-02-15 Sebastian Wilhelmi + + * acconfig.h, configure.in: Reverted the changes necessary to + enlarge the system thread for G_THREAD_USE_PID_SURROGATE. + + * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c + instead of gthread/gthread-posix.c. While the latter has the + advantage, that it is conceptually cleaner, it makes + g_thread_self_posix_impl _very_ slow and that hurts + GStaticRecMutex and other things. So the new version is less + clean, but faster. + 2001-02-09 Havoc Pennington * gconvert.c (g_convert): don't overwrite errors diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 0e9bc0d..d36fa0c 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,15 @@ +2001-02-15 Sebastian Wilhelmi + + * acconfig.h, configure.in: Reverted the changes necessary to + enlarge the system thread for G_THREAD_USE_PID_SURROGATE. + + * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c + instead of gthread/gthread-posix.c. While the latter has the + advantage, that it is conceptually cleaner, it makes + g_thread_self_posix_impl _very_ slow and that hurts + GStaticRecMutex and other things. So the new version is less + clean, but faster. + 2001-02-09 Havoc Pennington * gconvert.c (g_convert): don't overwrite errors diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 0e9bc0d..d36fa0c 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,15 @@ +2001-02-15 Sebastian Wilhelmi + + * acconfig.h, configure.in: Reverted the changes necessary to + enlarge the system thread for G_THREAD_USE_PID_SURROGATE. + + * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c + instead of gthread/gthread-posix.c. While the latter has the + advantage, that it is conceptually cleaner, it makes + g_thread_self_posix_impl _very_ slow and that hurts + GStaticRecMutex and other things. So the new version is less + clean, but faster. + 2001-02-09 Havoc Pennington * gconvert.c (g_convert): don't overwrite errors diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 0e9bc0d..d36fa0c 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,15 @@ +2001-02-15 Sebastian Wilhelmi + + * acconfig.h, configure.in: Reverted the changes necessary to + enlarge the system thread for G_THREAD_USE_PID_SURROGATE. + + * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c + instead of gthread/gthread-posix.c. While the latter has the + advantage, that it is conceptually cleaner, it makes + g_thread_self_posix_impl _very_ slow and that hurts + GStaticRecMutex and other things. So the new version is less + clean, but faster. + 2001-02-09 Havoc Pennington * gconvert.c (g_convert): don't overwrite errors diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 0e9bc0d..d36fa0c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,15 @@ +2001-02-15 Sebastian Wilhelmi + + * acconfig.h, configure.in: Reverted the changes necessary to + enlarge the system thread for G_THREAD_USE_PID_SURROGATE. + + * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c + instead of gthread/gthread-posix.c. While the latter has the + advantage, that it is conceptually cleaner, it makes + g_thread_self_posix_impl _very_ slow and that hurts + GStaticRecMutex and other things. So the new version is less + clean, but faster. + 2001-02-09 Havoc Pennington * gconvert.c (g_convert): don't overwrite errors diff --git a/acconfig.h b/acconfig.h index d0e2fd2..b0f75be 100644 --- a/acconfig.h +++ b/acconfig.h @@ -45,7 +45,6 @@ #undef ENABLE_NLS #undef GETTEXT_PACKAGE -#undef GLIB_SIZEOF_SYSTEM_THREAD #undef GLIB_LOCALE_DIR #undef HAVE_GETTEXT #undef HAVE_LC_MESSAGES diff --git a/configure.in b/configure.in index d5105ca..334132a 100644 --- a/configure.in +++ b/configure.in @@ -1064,7 +1064,7 @@ if test x"$have_threads" != xnone; then glib_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $GTHREAD_COMPILE_IMPL_DEFINES" dnl we might grow sizeof(pthread_t) later on, so use a dummy name here - GLIB_SIZEOF([#include ], pthread_t, core_system_thread) + GLIB_SIZEOF([#include ], pthread_t, system_thread) # This is not AC_CHECK_FUNC to also work with function # name mangling in header files. AC_MSG_CHECKING(for pthread_attr_setstacksize) @@ -1118,7 +1118,6 @@ if test x"$have_threads" != xnone; then CPPFLAGS="$glib_save_CPPFLAGS" AC_MSG_CHECKING(whether to use the PID niceness surrogate for thread priorities) - glib_system_thread_size_growth=0 AC_TRY_RUN([#include #include #include @@ -1135,12 +1134,8 @@ if test x"$have_threads" != xnone; then }], [AC_MSG_RESULT(yes), AC_DEFINE(G_THREAD_USE_PID_SURROGATE, 1, [whether to use the PID niceness surrogate for thread priorities]) - glib_system_thread_size_growth=$ac_cv_sizeof_long ], [AC_MSG_RESULT(no)]) - dnl make sure both glib_cv_sizeof_system_thread and GLIB_SIZEOF_SYSTEM_THREAD are setup - glib_cv_sizeof_system_thread=`expr $glib_cv_sizeof_core_system_thread + $glib_system_thread_size_growth` - AC_DEFINE_UNQUOTED(GLIB_SIZEOF_SYSTEM_THREAD, $glib_cv_sizeof_system_thread) else # solaris threads GLIB_SIZEOF([#include ], thread_t, system_thread) fi diff --git a/glib/gthread.c b/glib/gthread.c index 7ec6568..aa37412 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -35,6 +35,13 @@ #include "config.h" #include "glib.h" +#ifdef G_THREAD_USE_PID_SURROGATE +#include +#include +#include +#include +#endif /* G_THREAD_USE_PID_SURROGATE */ + #ifdef HAVE_UNISTD_H #include #endif @@ -68,8 +75,24 @@ struct _GRealThread gpointer arg; gpointer private_data; GSystemThread system_thread; +#ifdef G_THREAD_USE_PID_SURROGATE + pid_t pid; +#endif /* G_THREAD_USE_PID_SURROGATE */ }; +#ifdef G_THREAD_USE_PID_SURROGATE +static gint priority_map[] = { 15, 0, -15, -20 }; +static gboolean prio_warned = FALSE; +# define SET_PRIO(pid, prio) G_STMT_START{ \ + gint error = setpriority (PRIO_PROCESS, (pid), priority_map[prio]); \ + if (error == -1 && errno == EACCES && !prio_warned) \ + { \ + prio_warned = TRUE; \ + g_warning ("Priorities can only be increased by root."); \ + } \ + }G_STMT_END +#endif /* G_THREAD_USE_PID_SURROGATE */ + typedef struct _GStaticPrivateNode GStaticPrivateNode; struct _GStaticPrivateNode { @@ -485,6 +508,10 @@ g_thread_create_proxy (gpointer data) g_assert (data); +#ifdef G_THREAD_USE_PID_SURROGATE + thread->pid = getpid (); +#endif /* G_THREAD_USE_PID_SURROGATE */ + /* This has to happen before G_LOCK, as that might call g_thread_self */ g_private_set (g_thread_specific_private, data); @@ -492,6 +519,9 @@ g_thread_create_proxy (gpointer data) before thread->func is called. See g_thread_create. */ G_LOCK (g_thread); G_UNLOCK (g_thread); + + if (g_thread_use_default_impl) + SET_PRIO (thread->pid, thread->thread.priority); thread->func (thread->arg); } @@ -573,7 +603,14 @@ g_thread_set_priority (GThread* thread, g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT); thread->priority = priority; - G_THREAD_CF (thread_set_priority, (void)0, (&real->system_thread, priority)); + +#ifdef G_THREAD_USE_PID_SURROGATE + if (g_thread_use_default_impl) + SET_PRIO (real->pid, priority); + else +#endif /* G_THREAD_USE_PID_SURROGATE */ + G_THREAD_CF (thread_set_priority, (void)0, + (&real->system_thread, priority)); } GThread* @@ -598,6 +635,10 @@ g_thread_self (void) if (g_thread_supported ()) G_THREAD_UF (thread_self, (&thread->system_thread)); +#ifdef G_THREAD_USE_PID_SURROGATE + thread->pid = getpid (); +#endif /* G_THREAD_USE_PID_SURROGATE */ + g_private_set (g_thread_specific_private, thread); G_LOCK (g_thread); diff --git a/gthread.c b/gthread.c index 7ec6568..aa37412 100644 --- a/gthread.c +++ b/gthread.c @@ -35,6 +35,13 @@ #include "config.h" #include "glib.h" +#ifdef G_THREAD_USE_PID_SURROGATE +#include +#include +#include +#include +#endif /* G_THREAD_USE_PID_SURROGATE */ + #ifdef HAVE_UNISTD_H #include #endif @@ -68,8 +75,24 @@ struct _GRealThread gpointer arg; gpointer private_data; GSystemThread system_thread; +#ifdef G_THREAD_USE_PID_SURROGATE + pid_t pid; +#endif /* G_THREAD_USE_PID_SURROGATE */ }; +#ifdef G_THREAD_USE_PID_SURROGATE +static gint priority_map[] = { 15, 0, -15, -20 }; +static gboolean prio_warned = FALSE; +# define SET_PRIO(pid, prio) G_STMT_START{ \ + gint error = setpriority (PRIO_PROCESS, (pid), priority_map[prio]); \ + if (error == -1 && errno == EACCES && !prio_warned) \ + { \ + prio_warned = TRUE; \ + g_warning ("Priorities can only be increased by root."); \ + } \ + }G_STMT_END +#endif /* G_THREAD_USE_PID_SURROGATE */ + typedef struct _GStaticPrivateNode GStaticPrivateNode; struct _GStaticPrivateNode { @@ -485,6 +508,10 @@ g_thread_create_proxy (gpointer data) g_assert (data); +#ifdef G_THREAD_USE_PID_SURROGATE + thread->pid = getpid (); +#endif /* G_THREAD_USE_PID_SURROGATE */ + /* This has to happen before G_LOCK, as that might call g_thread_self */ g_private_set (g_thread_specific_private, data); @@ -492,6 +519,9 @@ g_thread_create_proxy (gpointer data) before thread->func is called. See g_thread_create. */ G_LOCK (g_thread); G_UNLOCK (g_thread); + + if (g_thread_use_default_impl) + SET_PRIO (thread->pid, thread->thread.priority); thread->func (thread->arg); } @@ -573,7 +603,14 @@ g_thread_set_priority (GThread* thread, g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT); thread->priority = priority; - G_THREAD_CF (thread_set_priority, (void)0, (&real->system_thread, priority)); + +#ifdef G_THREAD_USE_PID_SURROGATE + if (g_thread_use_default_impl) + SET_PRIO (real->pid, priority); + else +#endif /* G_THREAD_USE_PID_SURROGATE */ + G_THREAD_CF (thread_set_priority, (void)0, + (&real->system_thread, priority)); } GThread* @@ -598,6 +635,10 @@ g_thread_self (void) if (g_thread_supported ()) G_THREAD_UF (thread_self, (&thread->system_thread)); +#ifdef G_THREAD_USE_PID_SURROGATE + thread->pid = getpid (); +#endif /* G_THREAD_USE_PID_SURROGATE */ + g_private_set (g_thread_specific_private, thread); G_LOCK (g_thread); diff --git a/gthread/ChangeLog b/gthread/ChangeLog index 48ecf73..3675496 100644 --- a/gthread/ChangeLog +++ b/gthread/ChangeLog @@ -1,3 +1,8 @@ +2001-02-15 Sebastian Wilhelmi + + * gthread-posix.c: Removed the G_THREAD_USE_PID_SURROGATE + implementation, which is now in gthread.c. + 2001-01-30 Sebastian Wilhelmi * gthread-impl.c (g_thread_init_with_errorcheck_mutexes): Call diff --git a/gthread/gthread-posix.c b/gthread/gthread-posix.c index fd3d758..1b2cb81 100644 --- a/gthread/gthread-posix.c +++ b/gthread/gthread-posix.c @@ -45,15 +45,6 @@ #include #endif -#ifdef G_THREAD_USE_PID_SURROGATE -# include -# define PID_IN_THREAD(thread) (*(pid_t*)(((gchar*)thread)+sizeof(pthread_t))) -# define SET_PRIO(pid, prio) \ - posix_check_cmd_prio ((setpriority (PRIO_PROCESS, (pid), \ - g_thread_priority_map [prio]) == -1) ? \ - (errno == EACCES ? EPERM : errno ): 0) -#endif /* G_THREAD_USE_PID_SURROGATE */ - #define posix_check_err(err, name) G_STMT_START{ \ int error = (err); \ if (error) \ @@ -104,12 +95,7 @@ static gboolean posix_check_cmd_prio_warned = FALSE; # error This should not happen. Contact the GLib team. #endif -#ifdef G_THREAD_USE_PID_SURROGATE -# define PRIORITY_LOW_VALUE 15 -# define PRIORITY_NORMAL_VALUE 0 -# define PRIORITY_HIGH_VALUE -15 -# define PRIORITY_URGENT_VALUE -20 -#elif defined (POSIX_MIN_PRIORITY) && defined (POSIX_MAX_PRIORITY) +#if defined (POSIX_MIN_PRIORITY) && defined (POSIX_MAX_PRIORITY) # define HAVE_PRIORITIES 1 # define PRIORITY_LOW_VALUE POSIX_MIN_PRIORITY # define PRIORITY_URGENT_VALUE POSIX_MAX_PRIORITY @@ -265,27 +251,6 @@ g_private_get_posix_impl (GPrivate * private_key) #endif } -#ifdef G_THREAD_USE_PID_SURROGATE -struct proxy_data -{ - GThreadFunc thread_func; - gpointer arg; - gpointer thread; - GThreadPriority priority; -}; - -static void -g_thread_create_posix_impl_proxy (struct proxy_data *data) -{ - GThreadFunc thread_func = data->thread_func; - GThreadFunc arg = data->arg; - PID_IN_THREAD (data->thread) = getpid(); - SET_PRIO (PID_IN_THREAD (data->thread), data->priority); - g_free (data); - thread_func (arg); -} -#endif /* G_THREAD_USE_PID_SURROGATE */ - static void g_thread_create_posix_impl (GThreadFunc thread_func, gpointer arg, @@ -325,35 +290,21 @@ g_thread_create_posix_impl (GThreadFunc thread_func, joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED)); #endif /* G_THREADS_IMPL_POSIX */ -#ifdef G_THREAD_USE_PID_SURROGATE - { - struct proxy_data *data = g_new (struct proxy_data, 1); - data->thread_func = thread_func; - data->arg = arg; - data->thread = thread; - data->priority = priority; - PID_IN_THREAD (thread) = 0; - ret = posix_error (pthread_create (thread, &attr, (void* (*)(void*)) - g_thread_create_posix_impl_proxy, - data)); - } -#else /* G_THREAD_USE_PID_SURROGATE */ -# ifdef HAVE_PRIORITIES -# ifdef G_THREADS_IMPL_POSIX +#ifdef HAVE_PRIORITIES +# ifdef G_THREADS_IMPL_POSIX { struct sched_param sched; posix_check_cmd (pthread_attr_getschedparam (&attr, &sched)); sched.sched_priority = g_thread_priority_map [priority]; posix_check_cmd_prio (pthread_attr_setschedparam (&attr, &sched)); } -# else /* G_THREADS_IMPL_DCE */ +# else /* G_THREADS_IMPL_DCE */ posix_check_cmd_prio (pthread_attr_setprio (&attr, g_thread_priority_map [priority])); -# endif /* G_THREADS_IMPL_DCE */ -# endif /* HAVE_PRIORITIES */ +# endif /* G_THREADS_IMPL_DCE */ +#endif /* HAVE_PRIORITIES */ ret = posix_error (pthread_create (thread, &attr, (void* (*)(void*))thread_func, arg)); -#endif /* !G_THREAD_USE_PID_SURROGATE */ posix_check_cmd (pthread_attr_destroy (&attr)); @@ -411,21 +362,13 @@ g_thread_set_priority_posix_impl (gpointer thread, GThreadPriority priority) posix_check_cmd_prio (pthread_setprio (*(pthread_t*)thread, g_thread_priority_map [priority])); # endif -#elif defined (G_THREAD_USE_PID_SURROGATE) - /* If the addressed thread hasn't yet been able to provide it's pid, - * we ignore the request. Should be more than rare */ - if (PID_IN_THREAD (thread) != 0) - SET_PRIO (PID_IN_THREAD (thread), priority); -#endif /* G_THREAD_USE_PID_SURROGATE */ +#endif /* HAVE_PRIORITIES */ } static void g_thread_self_posix_impl (gpointer thread) { *(pthread_t*)thread = pthread_self(); -#ifdef G_THREAD_USE_PID_SURROGATE - PID_IN_THREAD (thread) = getpid(); -#endif /* G_THREAD_USE_PID_SURROGATE */ } static GThreadFunctions g_thread_functions_for_glib_use_default =