Module Name: src Committed By: ad Date: Thu Jun 11 18:42:02 UTC 2020
Modified Files: src/lib/libpthread: pthread.c pthread_tsd.c Log Message: Drop self->pt_lock before clearing TSD / malloc TSD. To generate a diff of this commit: cvs rdiff -u -r1.175 -r1.176 src/lib/libpthread/pthread.c cvs rdiff -u -r1.22 -r1.23 src/lib/libpthread/pthread_tsd.c 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.175 src/lib/libpthread/pthread.c:1.176 --- src/lib/libpthread/pthread.c:1.175 Wed Jun 10 22:45:15 2020 +++ src/lib/libpthread/pthread.c Thu Jun 11 18:42:02 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $ */ +/* $NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $ */ /*- * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020 @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $"); +__RCSID("$NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $"); #define __EXPOSE_STACK 1 @@ -615,21 +615,18 @@ pthread_exit(void *retval) pthread_mutex_lock(&self->pt_lock); self->pt_flags |= PT_FLAG_CS_DISABLED; self->pt_cancel = 0; + pthread_mutex_unlock(&self->pt_lock); /* Call any cancellation cleanup handlers */ if (!PTQ_EMPTY(&self->pt_cleanup_stack)) { - pthread_mutex_unlock(&self->pt_lock); while (!PTQ_EMPTY(&self->pt_cleanup_stack)) { cleanup = PTQ_FIRST(&self->pt_cleanup_stack); PTQ_REMOVE(&self->pt_cleanup_stack, cleanup, ptc_next); (*cleanup->ptc_cleanup)(cleanup->ptc_arg); } - pthread_mutex_lock(&self->pt_lock); } - pthread_mutex_unlock(&self->pt_lock); __cxa_thread_run_atexit(); - pthread_mutex_lock(&self->pt_lock); /* Perform cleanup of thread-specific data */ pthread__destroy_tsd(self); @@ -641,6 +638,7 @@ pthread_exit(void *retval) * Signal our exit. Our stack and pthread_t won't be reused until * pthread_create() can see from kernel info that this LWP is gone. */ + pthread_mutex_lock(&self->pt_lock); self->pt_exitval = retval; if (self->pt_flags & PT_FLAG_DETACHED) { /* pthread__reap() will drop the lock. */ Index: src/lib/libpthread/pthread_tsd.c diff -u src/lib/libpthread/pthread_tsd.c:1.22 src/lib/libpthread/pthread_tsd.c:1.23 --- src/lib/libpthread/pthread_tsd.c:1.22 Sun Apr 19 20:47:03 2020 +++ src/lib/libpthread/pthread_tsd.c Thu Jun 11 18:42:02 2020 @@ -1,7 +1,7 @@ -/* $NetBSD: pthread_tsd.c,v 1.22 2020/04/19 20:47:03 joerg Exp $ */ +/* $NetBSD: pthread_tsd.c,v 1.23 2020/06/11 18:42:02 ad Exp $ */ /*- - * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc. + * Copyright (c) 2001, 2007, 2020 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_tsd.c,v 1.22 2020/04/19 20:47:03 joerg Exp $"); +__RCSID("$NetBSD: pthread_tsd.c,v 1.23 2020/06/11 18:42:02 ad Exp $"); /* Functions and structures dealing with thread-specific data */ #include <errno.h> @@ -323,7 +323,6 @@ pthread__destroy_tsd(pthread_t self) if (!self->pt_havespecific) return; - pthread_mutex_unlock(&self->pt_lock); /* Butenhof, section 5.4.2 (page 167): * @@ -378,7 +377,6 @@ pthread__destroy_tsd(pthread_t self) } while (!done && --iterations); self->pt_havespecific = 0; - pthread_mutex_lock(&self->pt_lock); } void