Module Name: src
Committed By: ad
Date: Sun Mar 29 09:30:05 UTC 2009
Modified Files:
src/lib/libpthread: pthread.c
src/lib/libpthread/arch/i386: pthread_md.c pthread_md.h
Log Message:
- Make the threadreg code use _lwp_setprivate() instead of MD hooks.
XXX This must not be enabled by default because the LWP private mechanism
is reserved for TLS. It is provided only as a test/demo.
XXX Since ucontext_t does not contain the thread private variable, for a
short time after threads are created their thread specific data is unset.
If a signal arrives during that time we are screwed.
- No longer need pthread__osrev.
- Rearrange _lwp_ctl() calls slightly.
To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libpthread/arch/i386/pthread_md.c
cvs rdiff -u -r1.15 -r1.16 src/lib/libpthread/arch/i386/pthread_md.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libpthread/pthread.c
diff -u src/lib/libpthread/pthread.c:1.106 src/lib/libpthread/pthread.c:1.107
--- src/lib/libpthread/pthread.c:1.106 Wed Oct 8 10:03:28 2008
+++ src/lib/libpthread/pthread.c Sun Mar 29 09:30:05 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread.c,v 1.106 2008/10/08 10:03:28 ad Exp $ */
+/* $NetBSD: pthread.c,v 1.107 2009/03/29 09:30:05 ad Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread.c,v 1.106 2008/10/08 10:03:28 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.107 2009/03/29 09:30:05 ad Exp $");
#define __EXPOSE_STACK 1
@@ -68,7 +68,6 @@
static int pthread__stackid_setup(void *, size_t, pthread_t *);
static int pthread__stackalloc(pthread_t *);
static void pthread__initmain(pthread_t *);
-static void pthread__fork_callback(void);
static void pthread__reap(pthread_t);
static void pthread__child_callback(void);
static void pthread__start(void);
@@ -95,7 +94,6 @@
int pthread__concurrency;
int pthread__nspins;
int pthread__unpark_max = PTHREAD__UNPARK_MAX;
-int pthread__osrev;
/*
* We have to initialize the pthread_stack* variables here because
@@ -169,10 +167,6 @@
mib[0] = CTL_KERN;
mib[1] = KERN_OSREV;
- len = sizeof(pthread__osrev);
- if (sysctl(mib, 2, &pthread__osrev, &len, NULL, 0) == -1)
- err(1, "sysctl(hw.osrevision");
-
/* Initialize locks first; they're needed elsewhere. */
pthread__lockprim_init();
for (i = 0; i < NHASHLOCK; i++) {
@@ -201,10 +195,6 @@
PTQ_INSERT_HEAD(&pthread__allqueue, first, pt_allq);
RB_INSERT(__pthread__alltree, &pthread__alltree, first);
- if (_lwp_ctl(LWPCTL_FEATURE_CURCPU, &first->pt_lwpctl) != 0) {
- err(1, "_lwp_ctl");
- }
-
/* Start subsystems */
PTHREAD_MD_INIT
@@ -233,23 +223,15 @@
/* Tell libc that we're here and it should role-play accordingly. */
pthread__first = first;
- pthread_atfork(NULL, NULL, pthread__fork_callback);
__isthreaded = 1;
}
static void
-pthread__fork_callback(void)
+pthread__child_callback(void)
{
/* lwpctl state is not copied across fork. */
- if (_lwp_ctl(LWPCTL_FEATURE_CURCPU, &pthread__first->pt_lwpctl)) {
- err(1, "_lwp_ctl");
- }
-}
-
-static void
-pthread__child_callback(void)
-{
+ pthread__first->pt_lwpctl = &pthread__dummy_lwpctl;
/*
* Clean up data structures that a forked child process might
@@ -273,6 +255,9 @@
* various restrictions on fork() and threads, it's legal to
* fork() before creating any threads.
*/
+ if (_lwp_ctl(LWPCTL_FEATURE_CURCPU, &pthread__first->pt_lwpctl)) {
+ err(1, "_lwp_ctl");
+ }
pthread_atfork(NULL, NULL, pthread__child_callback);
}
@@ -449,10 +434,11 @@
{
void *retval;
-#ifdef PTHREAD__HAVE_THREADREG
- /* Set up identity register. */
- pthread__threadreg_set(self);
-#endif
+ /*
+ * Set up identity register.
+ * XXX Race: could receive a signal before this.
+ */
+ (void)_lwp_setprivate(self);
/*
* Throw away some stack in a feeble attempt to reduce cache
@@ -1238,10 +1224,8 @@
*newt = t;
-#ifdef PTHREAD__HAVE_THREADREG
/* Set up identity register. */
- pthread__threadreg_set(t);
-#endif
+ (void)_lwp_setprivate(t);
}
static int
Index: src/lib/libpthread/arch/i386/pthread_md.c
diff -u src/lib/libpthread/arch/i386/pthread_md.c:1.5 src/lib/libpthread/arch/i386/pthread_md.c:1.6
--- src/lib/libpthread/arch/i386/pthread_md.c:1.5 Mon Apr 28 20:23:02 2008
+++ src/lib/libpthread/arch/i386/pthread_md.c Sun Mar 29 09:30:05 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_md.c,v 1.5 2008/04/28 20:23:02 martin Exp $ */
+/* $NetBSD: pthread_md.c,v 1.6 2009/03/29 09:30:05 ad Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_md.c,v 1.5 2008/04/28 20:23:02 martin Exp $");
+__RCSID("$NetBSD: pthread_md.c,v 1.6 2009/03/29 09:30:05 ad Exp $");
#include <sys/param.h>
#include <sys/sysctl.h>
@@ -73,10 +73,3 @@
}
}
-
-void
-pthread__threadreg_set(pthread_t self)
-{
-
- sysarch(I386_SET_GSBASE, &self);
-}
Index: src/lib/libpthread/arch/i386/pthread_md.h
diff -u src/lib/libpthread/arch/i386/pthread_md.h:1.15 src/lib/libpthread/arch/i386/pthread_md.h:1.16
--- src/lib/libpthread/arch/i386/pthread_md.h:1.15 Mon Jun 23 10:39:38 2008
+++ src/lib/libpthread/arch/i386/pthread_md.h Sun Mar 29 09:30:05 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_md.h,v 1.15 2008/06/23 10:39:38 ad Exp $ */
+/* $NetBSD: pthread_md.h,v 1.16 2009/03/29 09:30:05 ad Exp $ */
/*-
* Copyright (c) 2001, 2007, 2008 The NetBSD Foundation, Inc.
@@ -175,13 +175,11 @@
} while (/*CONSTCOND*/0)
#define pthread__smt_pause() __asm __volatile("rep; nop" ::: "memory")
-/* #define PTHREAD__HAVE_THREADREG */
+/* #define PTHREAD__HAVE_THREADREG */
/* Don't need additional memory barriers. */
#define PTHREAD__ATOMIC_IS_MEMBAR
-void pthread__threadreg_set(pthread_t);
-
static inline pthread_t
#ifdef __GNUC__
__attribute__ ((__const__))