mirror of
https://github.com/dborth/snes9xgx.git
synced 2025-01-11 18:59:08 +01:00
improve device thread
This commit is contained in:
parent
911881421b
commit
a8ad004214
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 ();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user