diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index 5171a45..d800351 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -49,7 +49,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 @@ -102,7 +130,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; } @@ -404,7 +435,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) @@ -418,7 +449,7 @@ LoadSzFile(char * filepath, unsigned char * rbuffer) } // go back to checking if devices were inserted/removed - LWP_ResumeThread (devicethread); + ResumeDeviceThread(); return size; } @@ -450,7 +481,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) @@ -526,7 +557,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; } @@ -562,7 +593,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) { @@ -598,7 +629,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 9584b60..237e56c 100644 --- a/source/ngc/fileop.h +++ b/source/ngc/fileop.h @@ -21,6 +21,8 @@ #define SAVEBUFFERSIZE (1024 * 1024 * 2) void InitDeviceThread(); +void ResumeDeviceThread(); +void HaltDeviceThread(); void MountAllFAT(); void UnmountAllFAT(); bool ChangeInterface(int method, bool silent); @@ -37,6 +39,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 5538282..232bf6e 100644 --- a/source/ngc/networkop.cpp +++ b/source/ngc/networkop.cpp @@ -129,7 +129,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]; @@ -160,7 +160,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/vba.cpp b/source/ngc/vba.cpp index 4b6d9dd..efeca47 100644 --- a/source/ngc/vba.cpp +++ b/source/ngc/vba.cpp @@ -61,7 +61,7 @@ static void ExitCleanup() ShutdownAudio(); StopGX(); - LWP_SuspendThread (devicethread); + HaltDeviceThread(); UnmountAllFAT(); #ifdef HW_RVL @@ -182,7 +182,6 @@ int main(int argc, char *argv[]) #endif #ifdef HW_RVL - DI_Close(); DI_Init(); // first #endif @@ -243,7 +242,7 @@ int main(int argc, char *argv[]) // go back to checking if devices were inserted/removed // since we're entering the menu - LWP_ResumeThread (devicethread); + ResumeDeviceThread(); ConfigRequested = 1; SwitchAudioMode(1); @@ -258,7 +257,7 @@ int main(int argc, char *argv[]) // stop checking if devices were removed/inserted // since we're starting emulation again - LWP_SuspendThread (devicethread); + HaltDeviceThread(); ResetVideo_Emu();