Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpthread Drop self->pt_lock before clearing TSD / mall...



details:   https://anonhg.NetBSD.org/src/rev/4557e945aafa
branches:  trunk
changeset: 972857:4557e945aafa
user:      ad <ad%NetBSD.org@localhost>
date:      Thu Jun 11 18:42:02 2020 +0000

description:
Drop self->pt_lock before clearing TSD / malloc TSD.

diffstat:

 lib/libpthread/pthread.c     |  10 ++++------
 lib/libpthread/pthread_tsd.c |   8 +++-----
 2 files changed, 7 insertions(+), 11 deletions(-)

diffs (87 lines):

diff -r bbd788477bef -r 4557e945aafa lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c  Thu Jun 11 18:41:22 2020 +0000
+++ b/lib/libpthread/pthread.c  Thu Jun 11 18:42:02 2020 +0000
@@ -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_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 @@
         * 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. */
diff -r bbd788477bef -r 4557e945aafa lib/libpthread/pthread_tsd.c
--- a/lib/libpthread/pthread_tsd.c      Thu Jun 11 18:41:22 2020 +0000
+++ b/lib/libpthread/pthread_tsd.c      Thu Jun 11 18:42:02 2020 +0000
@@ -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 @@
 
        if (!self->pt_havespecific)
                return;
-       pthread_mutex_unlock(&self->pt_lock);
 
        /* Butenhof, section 5.4.2 (page 167):
         * 
@@ -378,7 +377,6 @@
        } while (!done && --iterations);
 
        self->pt_havespecific = 0;
-       pthread_mutex_lock(&self->pt_lock);
 }
 
 void



Home | Main Index | Thread Index | Old Index