No CloseHandle on thread handles which were obtained via GetCurrentThreadId. WINCE_NSPRPUB_RELEASE_4_2_BETA1
authorblythe%netscape.com
Fri, 01 Mar 2002 00:07:59 +0000
branchWINCE_NSPRPUB_RELEASE_4_2_BETA1
changeset 2280 52dda25e27d19f0fa333d084e8009e38e29e4ca8
parent 2274 80cea48c45dafd8afc02cc7831523e73edb0e857
child 2323 7053546d500ada067fa1192211e39d279a2c29b6
push idunknown
push userunknown
push dateunknown
No CloseHandle on thread handles which were obtained via GetCurrentThreadId.
pr/include/md/_wince.h
pr/src/md/windows/w95thred.c
--- a/pr/include/md/_wince.h
+++ b/pr/include/md/_wince.h
@@ -94,16 +94,17 @@ struct _MDCPU {
 struct _MDThread {
     HANDLE           blocked_sema;      /* Threads block on this when waiting
                                          * for IO or CondVar.
                                          */
     PRBool           inCVWaitQueue;     /* PR_TRUE if the thread is in the
                                          * wait queue of some cond var.
                                          * PR_FALSE otherwise.  */
     HANDLE           handle;            /* Win32 thread handle */
+    PRBool           noCloseHandle;     /* Whether or not to CloseHandle */
     PRUint32         id;
     void            *sp;                /* only valid when suspended */
     PRUint32         magic;             /* for debugging */
     PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
     struct PRThread *prev, *next;       /* used by the cvar wait queue to
                                          * chain the PRThread structures
                                          * together */
 };
--- a/pr/src/md/windows/w95thred.c
+++ b/pr/src/md/windows/w95thred.c
@@ -99,16 +99,17 @@ PRStatus
                 0L,                      /* access flags */
                 FALSE,                   /* Inheritable */
                 DUPLICATE_SAME_ACCESS);  /* Options */
 #else
         /*
         ** On WinCE the thread ID is the same as the real thread handle.
         */
         thread->md.handle = (HANDLE)GetCurrentThreadId();
+        thread->md.noCloseHandle = PR_TRUE;
 #endif
     }
 
     /* Create the blocking IO semaphore */
     thread->md.blocked_sema = CreateSemaphore(NULL, 0, 1, NULL);
     if (thread->md.blocked_sema == NULL)
         return PR_FAILURE;
 	else
@@ -212,18 +213,23 @@ void
 
     if (thread->md.blocked_sema) {
         rv = CloseHandle(thread->md.blocked_sema);
         PR_ASSERT(rv);
         thread->md.blocked_sema = 0;
     }
 
     if (thread->md.handle) {
-        rv = CloseHandle(thread->md.handle);
-        PR_ASSERT(rv);
+        if(PR_FALSE == thread->md.noCloseHandle) {
+            rv = CloseHandle(thread->md.handle);
+            PR_ASSERT(rv);
+        }
+        else {
+            thread->md.noCloseHandle = PR_FALSE; /* reused? insurance.... */
+        }
         thread->md.handle = 0;
     }
 }
 
 void
 _PR_MD_EXIT_THREAD(PRThread *thread)
 {
     _PR_MD_CLEAN_THREAD(thread);