about summary refs log tree commit diff
path: root/nptl/sysdeps
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-12-27 07:38:25 +0000
committerUlrich Drepper <drepper@redhat.com>2003-12-27 07:38:25 +0000
commitcb5b9388dad6d0524322d45eafaa7b5d7b00b554 (patch)
treed1c543bdfe5bcaa0fb71816104857a9bcbead484 /nptl/sysdeps
parentdc8527f6475c8dd3682fd9203e91a01c77443463 (diff)
downloadglibc-cb5b9388dad6d0524322d45eafaa7b5d7b00b554.tar.gz
glibc-cb5b9388dad6d0524322d45eafaa7b5d7b00b554.tar.xz
glibc-cb5b9388dad6d0524322d45eafaa7b5d7b00b554.zip
Update.
2003-12-23  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/raise.c (raise): Protect pid = selftid
	setting with __ASSUME_TGKILL || defined __NR_tgkill.
	If pid is 0, set it to selftid.
	* sysdeps/unix/sysv/linux/getpid.c (really_getpid): Make inline.
	Don't set self->pid but self->tid.  If self->pid == 0 and self->tid
	!= 0, return self->tid without doing a syscall.
	* descr.h (struct pthread): Move pid field after tid.

	* Makefile (tests): Add tst-raise1.
	* tst-raise1.c: New file.
Diffstat (limited to 'nptl/sysdeps')
-rw-r--r--nptl/sysdeps/unix/sysv/linux/getpid.c40
-rw-r--r--nptl/sysdeps/unix/sysv/linux/raise.c6
2 files changed, 29 insertions, 17 deletions
diff --git a/nptl/sysdeps/unix/sysv/linux/getpid.c b/nptl/sysdeps/unix/sysv/linux/getpid.c
index 7efe3f2768..1c3532b7e1 100644
--- a/nptl/sysdeps/unix/sysv/linux/getpid.c
+++ b/nptl/sysdeps/unix/sysv/linux/getpid.c
@@ -23,32 +23,42 @@
 
 
 #ifndef NOT_IN_libc
-static pid_t really_getpid (pid_t oldval);
-#endif
-
+static inline __attribute__((always_inline)) pid_t really_getpid (pid_t oldval);
 
-pid_t
-__getpid (void)
+static inline __attribute__((always_inline)) pid_t
+really_getpid (pid_t oldval)
 {
-#ifndef NOT_IN_libc
-  pid_t result = THREAD_GETMEM (THREAD_SELF, pid);
-  if (__builtin_expect (result <= 0, 0))
-    result = really_getpid (result);
+  pid_t selftid;
+  if (__builtin_expect (oldval == 0
+			&& ((selftid = THREAD_GETMEM (THREAD_SELF, tid))
+			    != 0), 1))
+    return selftid;
+
+  INTERNAL_SYSCALL_DECL (err);
+  pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
+
+  /* We do not set the PID field in the TID here since we might be
+     called from a signal handler while the thread executes fork.  */
+  if (oldval == 0)
+    THREAD_SETMEM (THREAD_SELF, tid, result);
   return result;
 }
+#endif
 
-static pid_t
-really_getpid (pid_t oldval)
+pid_t
+__getpid (void)
 {
-#endif
+#ifdef NOT_IN_libc
   INTERNAL_SYSCALL_DECL (err);
   pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
-#ifndef NOT_IN_libc
-  if (oldval == 0)
-    THREAD_SETMEM (THREAD_SELF, pid, result);
+#else
+  pid_t result = THREAD_GETMEM (THREAD_SELF, pid);
+  if (__builtin_expect (result <= 0, 0))
+    result = really_getpid (result);
 #endif
   return result;
 }
+
 libc_hidden_def (__getpid)
 weak_alias (__getpid, getpid)
 libc_hidden_def (getpid)
diff --git a/nptl/sysdeps/unix/sysv/linux/raise.c b/nptl/sysdeps/unix/sysv/linux/raise.c
index 268ba87b29..ac54fa217e 100644
--- a/nptl/sysdeps/unix/sysv/linux/raise.c
+++ b/nptl/sysdeps/unix/sysv/linux/raise.c
@@ -44,17 +44,19 @@ raise (sig)
 #endif
       THREAD_SETMEM (pd, tid, selftid);
 
+#if __ASSUME_TGKILL || defined __NR_tgkill
       /* We do not set the PID field in the TID here since we might be
 	 called from a signal handler while the thread executes fork.  */
       pid = selftid;
+#endif
     }
 #if __ASSUME_TGKILL || defined __NR_tgkill
   else
     /* raise is an async-safe function.  It could be called while the
        fork function temporarily invalidated the PID field.  Adjust for
        that.  */
-    if (__builtin_expect (pid < 0, 0))
-      pid = -pid;
+    if (__builtin_expect (pid <= 0, 0))
+      pid = pid == 0 ? selftid : -pid;
 #endif
 
 #if __ASSUME_TGKILL