From: Gurusamy Sarathy Date: Wed, 15 Oct 1997 21:46:05 +0000 (+0000) Subject: Win32 changes over 5.004_52: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f6ac99e2a11804b59dd260e0bd29ad6b7cabfec6;p=p5sagit%2Fp5-mst-13.2.git Win32 changes over 5.004_52: - rearranged MUTEX_LOCK()s in perl_destroy so that we don't call it on an already locked mutex. - other minor tweaks. Now builds and runs win32-version of Thread_52, passing all tests. p4raw-id: //depot/win32/perl@135 --- diff --git a/perl.c b/perl.c index 901fda2..1049366 100644 --- a/perl.c +++ b/perl.c @@ -148,9 +148,6 @@ register PerlInterpreter *sv_interp; 0, FALSE, DUPLICATE_SAME_ACCESS); - /* XXX TlsAlloc() should probably be done in the DLL entry - * point also. - */ if ((thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) croak("panic: pthread_key_create"); if (TlsSetValue(thr_key, (LPVOID) thr) != TRUE) @@ -256,11 +253,11 @@ register PerlInterpreter *sv_interp; #ifdef USE_THREADS #ifndef FAKE_THREADS /* Join with any remaining non-detached threads */ - MUTEX_LOCK(&threads_mutex); DEBUG_L(PerlIO_printf(PerlIO_stderr(), "perl_destruct: waiting for %d threads...\n", nthreads - 1)); for (t = thr->next; t != thr; t = t->next) { + MUTEX_LOCK(&threads_mutex); MUTEX_LOCK(&t->mutex); switch (ThrSTATE(t)) { AV *av; @@ -271,7 +268,12 @@ register PerlInterpreter *sv_interp; MUTEX_UNLOCK(&t->mutex); nthreads--; MUTEX_UNLOCK(&threads_mutex); +#ifdef WIN32 + if ((WaitForSingleObject(t->Tself,INFINITE) == WAIT_FAILED) + || (GetExitCodeThread(t->Tself,(LPDWORD)&av) == 0)) +#else if (pthread_join(t->Tself, (void**)&av)) +#endif croak("panic: pthread_join failed during global destruction"); SvREFCNT_dec((SV*)av); DEBUG_L(PerlIO_printf(PerlIO_stderr(), @@ -300,6 +302,7 @@ register PerlInterpreter *sv_interp; /* fall through and out */ } } + MUTEX_LOCK(&threads_mutex); /* Now wait for the thread count nthreads to drop to one */ while (nthreads > 1) { diff --git a/thread.h b/thread.h index 68d919a..4fc37c9 100644 --- a/thread.h +++ b/thread.h @@ -112,8 +112,10 @@ typedef HANDLE perl_thread; #define DETACH(t) \ STMT_START { \ - if (CloseHandle((t)->Tself) == 0) \ + if (CloseHandle((t)->Tself) == 0) { \ + MUTEX_UNLOCK(&(t)->mutex); \ croak("panic: DETACH"); \ + } \ } STMT_END #define THR ((struct thread *) TlsGetValue(thr_key))