improve device thread

This commit is contained in:
dborth 2009-05-06 17:28:50 +00:00
parent ba017944fa
commit 2838765896
4 changed files with 46 additions and 15 deletions

View File

@ -49,7 +49,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
@ -102,6 +130,9 @@ devicecallback (void *arg)
} }
} }
#endif #endif
if(deviceHalt)
LWP_SuspendThread(devicethread);
else
sleep(1); // suspend thread for 1 sec sleep(1); // suspend thread for 1 sec
} }
return NULL; return NULL;
@ -404,7 +435,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)
@ -418,7 +449,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;
} }
@ -450,7 +481,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)
@ -526,7 +557,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;
} }
@ -562,7 +593,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)
{ {
@ -598,7 +629,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;

View File

@ -21,6 +21,8 @@
#define SAVEBUFFERSIZE (1024 * 1024 * 2) #define SAVEBUFFERSIZE (1024 * 1024 * 2)
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);
@ -37,6 +39,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

View File

@ -129,7 +129,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];
@ -160,7 +160,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;
} }

View File

@ -61,7 +61,7 @@ static void ExitCleanup()
ShutdownAudio(); ShutdownAudio();
StopGX(); StopGX();
LWP_SuspendThread (devicethread); HaltDeviceThread();
UnmountAllFAT(); UnmountAllFAT();
#ifdef HW_RVL #ifdef HW_RVL
@ -182,7 +182,6 @@ int main(int argc, char *argv[])
#endif #endif
#ifdef HW_RVL #ifdef HW_RVL
DI_Close();
DI_Init(); // first DI_Init(); // first
#endif #endif
@ -243,7 +242,7 @@ int main(int argc, char *argv[])
// 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);
@ -258,7 +257,7 @@ int main(int argc, char *argv[])
// 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();
ResetVideo_Emu(); ResetVideo_Emu();