From 28a267e306abd2be1997d86e7b2d9d3c567e2674 Mon Sep 17 00:00:00 2001 From: Sebastian Wilhelmi Date: Wed, 25 Feb 2004 13:23:14 +0000 Subject: [PATCH] For the PID thread priorities surrogate use gettid instead of getpid. This 2004-02-25 Sebastian Wilhelmi * configure.in, glib/gthread.c: For the PID thread priorities surrogate use gettid instead of getpid. This also works with nptl (on linux-2.6), as well as with linuxthreads (on linux-2.4). --- ChangeLog | 6 ++++++ ChangeLog.pre-2-10 | 6 ++++++ ChangeLog.pre-2-12 | 6 ++++++ ChangeLog.pre-2-4 | 6 ++++++ ChangeLog.pre-2-6 | 6 ++++++ ChangeLog.pre-2-8 | 6 ++++++ configure.in | 9 ++++++--- glib/gthread.c | 18 ++++++++++-------- 8 files changed, 52 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index dcebdf3..1cc7578 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-02-25 Sebastian Wilhelmi + + * configure.in, glib/gthread.c: For the PID thread priorities + surrogate use gettid instead of getpid. This also works with nptl + (on linux-2.6), as well as with linuxthreads (on linux-2.4). + 2004-02-24 Sebastian Wilhelmi * glib/grand.c: Add Since: 2.4, where due diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index dcebdf3..1cc7578 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +2004-02-25 Sebastian Wilhelmi + + * configure.in, glib/gthread.c: For the PID thread priorities + surrogate use gettid instead of getpid. This also works with nptl + (on linux-2.6), as well as with linuxthreads (on linux-2.4). + 2004-02-24 Sebastian Wilhelmi * glib/grand.c: Add Since: 2.4, where due diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index dcebdf3..1cc7578 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,9 @@ +2004-02-25 Sebastian Wilhelmi + + * configure.in, glib/gthread.c: For the PID thread priorities + surrogate use gettid instead of getpid. This also works with nptl + (on linux-2.6), as well as with linuxthreads (on linux-2.4). + 2004-02-24 Sebastian Wilhelmi * glib/grand.c: Add Since: 2.4, where due diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index dcebdf3..1cc7578 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +2004-02-25 Sebastian Wilhelmi + + * configure.in, glib/gthread.c: For the PID thread priorities + surrogate use gettid instead of getpid. This also works with nptl + (on linux-2.6), as well as with linuxthreads (on linux-2.4). + 2004-02-24 Sebastian Wilhelmi * glib/grand.c: Add Since: 2.4, where due diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index dcebdf3..1cc7578 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +2004-02-25 Sebastian Wilhelmi + + * configure.in, glib/gthread.c: For the PID thread priorities + surrogate use gettid instead of getpid. This also works with nptl + (on linux-2.6), as well as with linuxthreads (on linux-2.4). + 2004-02-24 Sebastian Wilhelmi * glib/grand.c: Add Since: 2.4, where due diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index dcebdf3..1cc7578 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +2004-02-25 Sebastian Wilhelmi + + * configure.in, glib/gthread.c: For the PID thread priorities + surrogate use gettid instead of getpid. This also works with nptl + (on linux-2.6), as well as with linuxthreads (on linux-2.4). + 2004-02-24 Sebastian Wilhelmi * glib/grand.c: Add Since: 2.4, where due diff --git a/configure.in b/configure.in index f318b12..fc16232 100644 --- a/configure.in +++ b/configure.in @@ -1767,16 +1767,19 @@ int main () { [AC_TRY_RUN([ #include #include -#include +#include +#include +_syscall0(pid_t,gettid) + pid_t other_pid = 0; -void* func(void* data) {other_pid = getpid();} +void* func(void* data) {other_pid = gettid();} main() { pthread_t t; void *ret; pthread_create (&t, 0, func, NULL); pthread_join (t, &ret); - exit (getpid()==other_pid || + exit (gettid()==other_pid || $posix_priority_min != $posix_priority_max); } ], [glib_cv_use_pid_surrogate=yes], diff --git a/glib/gthread.c b/glib/gthread.c index 138bc32..545f4d2 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -39,6 +39,8 @@ #include #include #include +#include +_syscall0(pid_t,gettid) #endif /* G_THREAD_USE_PID_SURROGATE */ #ifdef HAVE_UNISTD_H @@ -85,15 +87,15 @@ struct _GRealThread gpointer retval; GSystemThread system_thread; #ifdef G_THREAD_USE_PID_SURROGATE - pid_t pid; + pid_t tid; #endif /* G_THREAD_USE_PID_SURROGATE */ }; #ifdef G_THREAD_USE_PID_SURROGATE static gint priority_map[4]; static gboolean prio_warned = FALSE; -# define SET_PRIO(pid, prio) G_STMT_START{ \ - gint error = setpriority (PRIO_PROCESS, (pid), priority_map[prio]); \ +# define SET_PRIO(tid, prio) G_STMT_START{ \ + gint error = setpriority (PRIO_PROCESS, (tid), priority_map[prio]); \ if (error == -1 && errno == EACCES && !prio_warned) \ { \ prio_warned = TRUE; \ @@ -179,7 +181,7 @@ g_thread_init_glib (void) #ifdef G_THREAD_USE_PID_SURROGATE priority_map[G_THREAD_PRIORITY_NORMAL] = - getpriority (PRIO_PROCESS, (getpid ())); + getpriority (PRIO_PROCESS, (gettid ())); priority_map[G_THREAD_PRIORITY_LOW] = MIN (20, priority_map[G_THREAD_PRIORITY_NORMAL] + 10); priority_map[G_THREAD_PRIORITY_HIGH] = @@ -582,7 +584,7 @@ g_thread_create_proxy (gpointer data) g_assert (data); #ifdef G_THREAD_USE_PID_SURROGATE - thread->pid = getpid (); + thread->tid = gettid (); #endif /* G_THREAD_USE_PID_SURROGATE */ /* This has to happen before G_LOCK, as that might call g_thread_self */ @@ -595,7 +597,7 @@ g_thread_create_proxy (gpointer data) #ifdef G_THREAD_USE_PID_SURROGATE if (g_thread_use_default_impl) - SET_PRIO (thread->pid, thread->thread.priority); + SET_PRIO (thread->tid, thread->thread.priority); #endif /* G_THREAD_USE_PID_SURROGATE */ thread->retval = thread->thread.func (thread->thread.data); @@ -697,7 +699,7 @@ g_thread_set_priority (GThread* thread, #ifdef G_THREAD_USE_PID_SURROGATE if (g_thread_use_default_impl) - SET_PRIO (real->pid, priority); + SET_PRIO (real->tid, priority); else #endif /* G_THREAD_USE_PID_SURROGATE */ G_THREAD_CF (thread_set_priority, (void)0, @@ -726,7 +728,7 @@ g_thread_self (void) G_THREAD_UF (thread_self, (&thread->system_thread)); #ifdef G_THREAD_USE_PID_SURROGATE - thread->pid = getpid (); + thread->tid = gettid (); #endif /* G_THREAD_USE_PID_SURROGATE */ g_private_set (g_thread_specific_private, thread); -- 2.7.4