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
|
* 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
|
* devicecallback
|
||||||
@ -104,7 +132,10 @@ devicecallback (void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
sleep(1); // suspend thread for 1 sec
|
if(deviceHalt)
|
||||||
|
LWP_SuspendThread(devicethread);
|
||||||
|
else
|
||||||
|
sleep(1); // suspend thread for 1 sec
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -406,7 +437,7 @@ LoadSzFile(char * filepath, unsigned char * rbuffer)
|
|||||||
|
|
||||||
// stop checking if devices were removed/inserted
|
// stop checking if devices were removed/inserted
|
||||||
// since we're loading a file
|
// since we're loading a file
|
||||||
LWP_SuspendThread (devicethread);
|
HaltDeviceThread();
|
||||||
|
|
||||||
file = fopen (filepath, "rb");
|
file = fopen (filepath, "rb");
|
||||||
if (file > 0)
|
if (file > 0)
|
||||||
@ -420,7 +451,7 @@ LoadSzFile(char * filepath, unsigned char * rbuffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// go back to checking if devices were inserted/removed
|
// go back to checking if devices were inserted/removed
|
||||||
LWP_ResumeThread (devicethread);
|
ResumeDeviceThread();
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@ -452,7 +483,7 @@ LoadFile (char * rbuffer, char *filepath, u32 length, int method, bool silent)
|
|||||||
|
|
||||||
// stop checking if devices were removed/inserted
|
// stop checking if devices were removed/inserted
|
||||||
// since we're loading a file
|
// since we're loading a file
|
||||||
LWP_SuspendThread (devicethread);
|
HaltDeviceThread();
|
||||||
|
|
||||||
// open the file
|
// open the file
|
||||||
while(!size && retry == 1)
|
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
|
// go back to checking if devices were inserted/removed
|
||||||
LWP_ResumeThread (devicethread);
|
ResumeDeviceThread();
|
||||||
CancelAction();
|
CancelAction();
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@ -564,7 +595,7 @@ SaveFile (char * buffer, char *filepath, u32 datasize, int method, bool silent)
|
|||||||
|
|
||||||
// stop checking if devices were removed/inserted
|
// stop checking if devices were removed/inserted
|
||||||
// since we're saving a file
|
// since we're saving a file
|
||||||
LWP_SuspendThread (devicethread);
|
HaltDeviceThread();
|
||||||
|
|
||||||
while(!written && retry == 1)
|
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
|
// go back to checking if devices were inserted/removed
|
||||||
LWP_ResumeThread (devicethread);
|
ResumeDeviceThread();
|
||||||
|
|
||||||
CancelAction();
|
CancelAction();
|
||||||
return written;
|
return written;
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#define SAVEBUFFERSIZE (1024 * 512)
|
#define SAVEBUFFERSIZE (1024 * 512)
|
||||||
|
|
||||||
void InitDeviceThread();
|
void InitDeviceThread();
|
||||||
|
void ResumeDeviceThread();
|
||||||
|
void HaltDeviceThread();
|
||||||
void MountAllFAT();
|
void MountAllFAT();
|
||||||
void UnmountAllFAT();
|
void UnmountAllFAT();
|
||||||
bool ChangeInterface(int method, bool silent);
|
bool ChangeInterface(int method, bool silent);
|
||||||
@ -40,6 +42,5 @@ extern unsigned char * savebuffer;
|
|||||||
extern FILE * file;
|
extern FILE * file;
|
||||||
extern bool unmountRequired[];
|
extern bool unmountRequired[];
|
||||||
extern bool isMounted[];
|
extern bool isMounted[];
|
||||||
extern lwp_t devicethread;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -146,7 +146,7 @@ bool DownloadUpdate()
|
|||||||
{
|
{
|
||||||
// stop checking if devices were removed/inserted
|
// stop checking if devices were removed/inserted
|
||||||
// since we're saving a file
|
// since we're saving a file
|
||||||
LWP_SuspendThread (devicethread);
|
HaltDeviceThread();
|
||||||
|
|
||||||
FILE * hfile;
|
FILE * hfile;
|
||||||
char updateFile[50];
|
char updateFile[50];
|
||||||
@ -177,7 +177,7 @@ bool DownloadUpdate()
|
|||||||
updateFound = false; // updating is finished (successful or not!)
|
updateFound = false; // updating is finished (successful or not!)
|
||||||
|
|
||||||
// go back to checking if devices were inserted/removed
|
// go back to checking if devices were inserted/removed
|
||||||
LWP_ResumeThread (devicethread);
|
ResumeDeviceThread();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ void ExitCleanup()
|
|||||||
ShutdownAudio();
|
ShutdownAudio();
|
||||||
StopGX();
|
StopGX();
|
||||||
|
|
||||||
LWP_SuspendThread (devicethread);
|
HaltDeviceThread();
|
||||||
UnmountAllFAT();
|
UnmountAllFAT();
|
||||||
|
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
@ -214,7 +214,7 @@ emulate ()
|
|||||||
{
|
{
|
||||||
// go back to checking if devices were inserted/removed
|
// go back to checking if devices were inserted/removed
|
||||||
// since we're entering the menu
|
// since we're entering the menu
|
||||||
LWP_ResumeThread (devicethread);
|
ResumeDeviceThread();
|
||||||
|
|
||||||
ConfigRequested = 1;
|
ConfigRequested = 1;
|
||||||
SwitchAudioMode(1);
|
SwitchAudioMode(1);
|
||||||
@ -238,7 +238,7 @@ emulate ()
|
|||||||
|
|
||||||
// stop checking if devices were removed/inserted
|
// stop checking if devices were removed/inserted
|
||||||
// since we're starting emulation again
|
// since we're starting emulation again
|
||||||
LWP_SuspendThread (devicethread);
|
HaltDeviceThread();
|
||||||
|
|
||||||
AudioStart ();
|
AudioStart ();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user