Skip to content
Snippets Groups Projects
Commit 4d414128 authored by rswindell's avatar rswindell
Browse files

Win32 CriticalSection implementation of pthread_mutex_unlock now checks the

LockCount before unlocking to prevent lock-up (indefinite wait) situation.
parent 29ce92a0
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment