Module Name: src Committed By: ad Date: Sun May 17 14:49:00 UTC 2009
Modified Files: src/lib/libpthread: pthread.c pthread_int.h Log Message: - Convert from makecontext() -> _lwp_makecontext(). - Rely on _lwp_makecontext() to set up the thread identity register. This is not currently done (a bug), nor does libpthread use the threadreg yet. I'm doing this so it the code can be used by the person working on TLS to verify that their threadreg code is working. To generate a diff of this commit: cvs rdiff -u -r1.109 -r1.110 src/lib/libpthread/pthread.c cvs rdiff -u -r1.71 -r1.72 src/lib/libpthread/pthread_int.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.109 src/lib/libpthread/pthread.c:1.110 --- src/lib/libpthread/pthread.c:1.109 Wed Apr 1 10:13:24 2009 +++ src/lib/libpthread/pthread.c Sun May 17 14:49:00 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: pthread.c,v 1.109 2009/04/01 10:13:24 drochner Exp $ */ +/* $NetBSD: pthread.c,v 1.110 2009/05/17 14:49:00 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.109 2009/04/01 10:13:24 drochner Exp $"); +__RCSID("$NetBSD: pthread.c,v 1.110 2009/05/17 14:49:00 ad Exp $"); #define __EXPOSE_STACK 1 @@ -62,7 +62,7 @@ RB_PROTOTYPE_STATIC(__pthread__alltree, __pthread_st, pt_alltree, pthread__cmp) #endif -static void pthread__create_tramp(pthread_t, void *(*)(void *), void *); +static void pthread__create_tramp(void *); static void pthread__initthread(pthread_t); static void pthread__scrubthread(pthread_t, char *, int); static int pthread__stackid_setup(void *, size_t, pthread_t *); @@ -406,8 +406,11 @@ * Create the new LWP. */ pthread__scrubthread(newthread, name, nattr.pta_flags); - makecontext(&newthread->pt_uc, pthread__create_tramp, 3, - newthread, startfunc, arg); + newthread->pt_func = startfunc; + newthread->pt_arg = arg; + _lwp_makecontext(&newthread->pt_uc, pthread__create_tramp, + newthread, newthread, newthread->pt_stack.ss_sp, + newthread->pt_stack.ss_size); flag = LWP_DETACHED; if ((newthread->pt_flags & PT_FLAG_SUSPENDED) != 0 || @@ -440,22 +443,21 @@ static void -pthread__create_tramp(pthread_t self, void *(*start)(void *), void *arg) +pthread__create_tramp(void *cookie) { + pthread_t self; void *retval; - /* - * Set up identity register. - * XXX Race: could receive a signal before this. - */ - (void)_lwp_setprivate(self); + self = cookie; /* * Throw away some stack in a feeble attempt to reduce cache * thrash. May help for SMT processors. XXX We should not * be allocating stacks on fixed 2MB boundaries. Needs a - * thread register or decent thread local storage. Note - * that pt_lid may not be set by this point, but we don't + * thread register or decent thread local storage. + * + * Note that we may race with the kernel in _lwp_create(), + * and so pt_lid can be unset at this point, but we don't * care. */ (void)alloca(((unsigned)self->pt_lid & 7) << 8); @@ -471,7 +473,7 @@ err(1, "_lwp_ctl"); } - retval = (*start)(arg); + retval = (*self->pt_func)(self->pt_arg); pthread_exit(retval); Index: src/lib/libpthread/pthread_int.h diff -u src/lib/libpthread/pthread_int.h:1.71 src/lib/libpthread/pthread_int.h:1.72 --- src/lib/libpthread/pthread_int.h:1.71 Sat May 16 22:21:18 2009 +++ src/lib/libpthread/pthread_int.h Sun May 17 14:49:00 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_int.h,v 1.71 2009/05/16 22:21:18 ad Exp $ */ +/* $NetBSD: pthread_int.h,v 1.72 2009/05/17 14:49:00 ad Exp $ */ /*- * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -106,6 +106,8 @@ struct pthread_lock_ops pt_lockops;/* Cached to avoid PIC overhead */ pthread_mutex_t *pt_droplock; /* Drop this lock if cancelled */ pthread_cond_t pt_joiners; /* Threads waiting to join. */ + void *(*pt_func)(void *);/* Function to call at start. */ + void *pt_arg; /* Argumen to pass at start. */ /* Threads to defer waking, usually until pthread_mutex_unlock(). */ lwpid_t pt_waiters[PTHREAD__UNPARK_MAX];