Bug 749849: Delete the _PT_PTHREAD_KEY_DELETE macro. Have PR_Cleanup call
authorwtc%google.com
Fri, 19 Oct 2012 23:20:08 +0000
changeset 4412 b79350d0261348ec6c5df53e64aada7f447127d7
parent 4411 2dcdce0418f053bd263a766aec37b9cd6e7cf9f6
child 4413 397e550ce17d03005b48f181e96ca90ccaeaf3c5
push idunknown
push userunknown
push dateunknown
bugs749849
Bug 749849: Delete the _PT_PTHREAD_KEY_DELETE macro. Have PR_Cleanup call pthread_key_delete if there is no other NSPR thread (system or foreign) around. TBR=kaie. Modified Files: pr/include/md/_pth.h pr/src/pthreads/ptthread.c
pr/include/md/_pth.h
pr/src/pthreads/ptthread.c
--- a/pr/include/md/_pth.h
+++ b/pr/include/md/_pth.h
@@ -125,29 +125,26 @@
 #error "pthreads is not supported for this architecture"
 #endif
 
 #if defined(_PR_DCETHREADS)
 #define _PT_PTHREAD_ATTR_INIT            pthread_attr_create
 #define _PT_PTHREAD_ATTR_DESTROY         pthread_attr_delete
 #define _PT_PTHREAD_CREATE(t, a, f, r)   pthread_create(t, a, f, r) 
 #define _PT_PTHREAD_KEY_CREATE           pthread_keycreate
-#define _PT_PTHREAD_KEY_DELETE           pthread_keydelete
-/* Set _PT_PTHREAD_KEY_DELETE to empty if pthread_keydelete isn't available */
 #define _PT_PTHREAD_ATTR_SETSCHEDPOLICY  pthread_attr_setsched
 #define _PT_PTHREAD_ATTR_GETSTACKSIZE(a, s) \
                                      (*(s) = pthread_attr_getstacksize(*(a)), 0)
 #define _PT_PTHREAD_GETSPECIFIC(k, r) \
 		pthread_getspecific((k), (pthread_addr_t *) &(r))
 #elif defined(_PR_PTHREADS)
 #define _PT_PTHREAD_ATTR_INIT            pthread_attr_init
 #define _PT_PTHREAD_ATTR_DESTROY         pthread_attr_destroy
 #define _PT_PTHREAD_CREATE(t, a, f, r)   pthread_create(t, &a, f, r) 
 #define _PT_PTHREAD_KEY_CREATE           pthread_key_create
-#define _PT_PTHREAD_KEY_DELETE           pthread_key_delete
 #define _PT_PTHREAD_ATTR_SETSCHEDPOLICY  pthread_attr_setschedpolicy
 #define _PT_PTHREAD_ATTR_GETSTACKSIZE(a, s) pthread_attr_getstacksize(a, s)
 #define _PT_PTHREAD_GETSPECIFIC(k, r)    (r) = pthread_getspecific(k)
 #else
 #error "Cannot determine pthread strategy"
 #endif
 
 #if defined(_PR_DCETHREADS)
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -38,17 +38,17 @@ static PRIntn pt_schedpriv = 0;
 extern PRLock *_pr_sleeplock;
 
 static struct _PT_Bookeeping
 {
     PRLock *ml;                 /* a lock to protect ourselves */
     PRCondVar *cv;              /* used to signal global things */
     PRInt32 system, user;       /* a count of the two different types */
     PRUintn this_many;          /* number of threads allowed for exit */
-    pthread_key_t key;          /* private private data key */
+    pthread_key_t key;          /* thread private data key */
     PRThread *first, *last;     /* list of threads we know about */
 #if defined(_PR_DCETHREADS) || defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
     PRInt32 minPrio, maxPrio;   /* range of scheduling priorities */
 #endif
 } pt_book = {0};
 
 static void _pt_thread_death(void *arg);
 static void _pt_thread_death_internal(void *arg, PRBool callDestructors);
@@ -970,17 +970,18 @@ void _PR_Fini(void)
         /*
          * PR_FALSE, because it is unsafe to call back to the 
          * thread private data destructors at final cleanup.
          */
         _pt_thread_death_internal(thred, PR_FALSE);
         rv = pthread_setspecific(pt_book.key, NULL);
         PR_ASSERT(0 == rv);
     }
-    _PT_PTHREAD_KEY_DELETE(pt_book.key);
+    rv = pthread_key_delete(pt_book.key);
+    PR_ASSERT(0 == rv);
     /* TODO: free other resources used by NSPR */
     /* _pr_initialized = PR_FALSE; */
 }  /* _PR_Fini */
 
 PR_IMPLEMENT(PRStatus) PR_Cleanup(void)
 {
     PRThread *me = PR_GetCurrentThread();
     int rv;
@@ -1010,24 +1011,26 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup(void)
         _PR_CleanupIO();
         _PR_CleanupCMon();
 
         _pt_thread_death(me);
         rv = pthread_setspecific(pt_book.key, NULL);
         PR_ASSERT(0 == rv);
         /*
          * I am not sure if it's safe to delete the cv and lock here,
-         * since there may still be "system" threads around. If this
-         * call isn't immediately prior to exiting, then there's a
-         * problem.
+         * since there may still be "system" or "foreign" threads
+         * around. If this call isn't immediately prior to exiting,
+         * then there's a problem.
          */
-        if (0 == pt_book.system)
+        if (0 == pt_book.system && NULL == pt_book.first)
         {
             PR_DestroyCondVar(pt_book.cv); pt_book.cv = NULL;
             PR_DestroyLock(pt_book.ml); pt_book.ml = NULL;
+            rv = pthread_key_delete(pt_book.key);
+            PR_ASSERT(0 == rv);
         }
         PR_DestroyLock(_pr_sleeplock);
         _pr_sleeplock = NULL;
         _PR_CleanupLayerCache();
         _PR_CleanupEnv();
 #ifdef _PR_ZONE_ALLOCATOR
         _PR_DestroyZones();
 #endif