From 4d4141285f1a691079c0bde1a091a52a320e1677 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Thu, 2 Jan 2003 06:56:06 +0000 Subject: [PATCH] Win32 CriticalSection implementation of pthread_mutex_unlock now checks the LockCount before unlocking to prevent lock-up (indefinite wait) situation. --- src/sbbs3/xtrn.cpp | 11 +++-------- src/xpdev/threadwrap.h | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/sbbs3/xtrn.cpp b/src/sbbs3/xtrn.cpp index 80641ce632..24c903683d 100644 --- a/src/sbbs3/xtrn.cpp +++ b/src/sbbs3/xtrn.cpp @@ -253,7 +253,6 @@ int sbbs_t::external(char* cmdline, long mode, char* startup_dir) bool was_online=true; bool rio_abortable_save; bool use_pipes=false; // NT-compatible console redirection - bool input_thread_mutex_locked=false; uint i; time_t hungup=0; HANDLE vxd=INVALID_HANDLE_VALUE; @@ -556,10 +555,8 @@ int sbbs_t::external(char* cmdline, long mode, char* startup_dir) fclose(fp); /* not temporary */ - if(!(mode&EX_INR)) { + if(!(mode&EX_INR)) pthread_mutex_lock(&input_thread_mutex); - input_thread_mutex_locked=true; - } } if(!CreateProcess( @@ -575,8 +572,7 @@ int sbbs_t::external(char* cmdline, long mode, char* startup_dir) &process_info // pointer to PROCESS_INFORMATION )) { XTRN_CLEANUP; - if(input_thread_mutex_locked) - pthread_mutex_unlock(&input_thread_mutex); + pthread_mutex_unlock(&input_thread_mutex); SetLastError(last_error); /* Restore LastError */ errormsg(WHERE, ERR_EXEC, realcmdline, mode); return(GetLastError()); @@ -924,8 +920,7 @@ int sbbs_t::external(char* cmdline, long mode, char* startup_dir) if(native) { ulong l=0; ioctlsocket(client_socket, FIONBIO, &l); - if(input_thread_mutex_locked) - pthread_mutex_unlock(&input_thread_mutex); + pthread_mutex_unlock(&input_thread_mutex); } curatr=~0; // Can't guarantee current attributes diff --git a/src/xpdev/threadwrap.h b/src/xpdev/threadwrap.h index accb941133..62b87aff52 100644 --- a/src/xpdev/threadwrap.h +++ b/src/xpdev/threadwrap.h @@ -74,7 +74,7 @@ extern "C" { typedef CRITICAL_SECTION pthread_mutex_t; #define pthread_mutex_init(pmtx,v) InitializeCriticalSection(pmtx) #define pthread_mutex_lock(pmtx) EnterCriticalSection(pmtx) - #define pthread_mutex_unlock(pmtx) LeaveCriticalSection(pmtx) + #define pthread_mutex_unlock(pmtx) if((pmtx)->LockCount) LeaveCriticalSection(pmtx) #define pthread_mutex_destroy(pmtx) DeleteCriticalSection(pmtx) #else /* Implemented as Win32 Mutexes (much slower) */ typedef HANDLE pthread_mutex_t; -- GitLab