diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index f71f44c..6aff2a7 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -51,7 +51,35 @@ bool isMounted[9] = { false, false, false, false, false, false, false, false, fa /**************************************************************************** * deviceThreading ***************************************************************************/ -lwp_t devicethread = LWP_THREAD_NULL; +static lwp_t devicethread = LWP_THREAD_NULL; +static bool deviceHalt = true; + +/**************************************************************************** + * ResumeDeviceThread + * + * Signals the device thread to start, and resumes the thread. + ***************************************************************************/ +void +ResumeDeviceThread() +{ + deviceHalt = false; + LWP_ResumeThread(devicethread); +} + +/**************************************************************************** + * HaltGui + * + * Signals the device thread to stop. + ***************************************************************************/ +void +HaltDeviceThread() +{ + deviceHalt = true; + + // wait for thread to finish + while(!LWP_ThreadIsSuspended(devicethread)) + usleep(100); +} /**************************************************************************** * devicecallback @@ -104,7 +132,10 @@ devicecallback (void *arg) } } #endif - sleep(1); // suspend thread for 1 sec + if(deviceHalt) + LWP_SuspendThread(devicethread); + else + sleep(1); // suspend thread for 1 sec } return NULL; } @@ -406,7 +437,7 @@ LoadSzFile(char * filepath, unsigned char * rbuffer) // stop checking if devices were removed/inserted // since we're loading a file - LWP_SuspendThread (devicethread); + HaltDeviceThread(); file = fopen (filepath, "rb"); if (file > 0) @@ -420,7 +451,7 @@ LoadSzFile(char * filepath, unsigned char * rbuffer) } // go back to checking if devices were inserted/removed - LWP_ResumeThread (devicethread); + ResumeDeviceThread(); return size; } @@ -452,7 +483,7 @@ LoadFile (char * rbuffer, char *filepath, u32 length, int method, bool silent) // stop checking if devices were removed/inserted // since we're loading a file - LWP_SuspendThread (devicethread); + HaltDeviceThread(); // open the file while(!size && retry == 1) @@ -528,7 +559,7 @@ LoadFile (char * rbuffer, char *filepath, u32 length, int method, bool silent) } // go back to checking if devices were inserted/removed - LWP_ResumeThread (devicethread); + ResumeDeviceThread(); CancelAction(); return size; } @@ -564,7 +595,7 @@ SaveFile (char * buffer, char *filepath, u32 datasize, int method, bool silent) // stop checking if devices were removed/inserted // since we're saving a file - LWP_SuspendThread (devicethread); + HaltDeviceThread(); while(!written && retry == 1) { @@ -600,7 +631,7 @@ SaveFile (char * buffer, char *filepath, u32 datasize, int method, bool silent) } // go back to checking if devices were inserted/removed - LWP_ResumeThread (devicethread); + ResumeDeviceThread(); CancelAction(); return written; diff --git a/source/ngc/fileop.h b/source/ngc/fileop.h index 7d2d19b..9768c7d 100644 --- a/source/ngc/fileop.h +++ b/source/ngc/fileop.h @@ -24,6 +24,8 @@ #define SAVEBUFFERSIZE (1024 * 512) void InitDeviceThread(); +void ResumeDeviceThread(); +void HaltDeviceThread(); void MountAllFAT(); void UnmountAllFAT(); bool ChangeInterface(int method, bool silent); @@ -40,6 +42,5 @@ extern unsigned char * savebuffer; extern FILE * file; extern bool unmountRequired[]; extern bool isMounted[]; -extern lwp_t devicethread; #endif diff --git a/source/ngc/networkop.cpp b/source/ngc/networkop.cpp index 8170a7e..000e4de 100644 --- a/source/ngc/networkop.cpp +++ b/source/ngc/networkop.cpp @@ -146,7 +146,7 @@ bool DownloadUpdate() { // stop checking if devices were removed/inserted // since we're saving a file - LWP_SuspendThread (devicethread); + HaltDeviceThread(); FILE * hfile; char updateFile[50]; @@ -177,7 +177,7 @@ bool DownloadUpdate() updateFound = false; // updating is finished (successful or not!) // go back to checking if devices were inserted/removed - LWP_ResumeThread (devicethread); + ResumeDeviceThread(); } return result; } diff --git a/source/ngc/snes9xGX.cpp b/source/ngc/snes9xGX.cpp index 262744c..2d1bbcc 100644 --- a/source/ngc/snes9xGX.cpp +++ b/source/ngc/snes9xGX.cpp @@ -84,7 +84,7 @@ void ExitCleanup() ShutdownAudio(); StopGX(); - LWP_SuspendThread (devicethread); + HaltDeviceThread(); UnmountAllFAT(); #ifdef HW_RVL @@ -214,7 +214,7 @@ emulate () { // go back to checking if devices were inserted/removed // since we're entering the menu - LWP_ResumeThread (devicethread); + ResumeDeviceThread(); ConfigRequested = 1; SwitchAudioMode(1); @@ -238,7 +238,7 @@ emulate () // stop checking if devices were removed/inserted // since we're starting emulation again - LWP_SuspendThread (devicethread); + HaltDeviceThread(); AudioStart ();