From 495a4188841c20f74a8f581beca1e1dad1240203 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 7 Dec 2004 00:06:59 +0000 Subject: [PATCH] Previously, the main mount loop was unlocking the thread and then immediately re-locking it. In some threads implementations (Linux 2.6), this causes the mount thread to hog the lock, which causes SetMountThreadState to hang. Move the "check and delay" part of the mount thread outside of the lock, so other threads have opportunity to get the lock. --- .../MemoryCard/MemoryCardDriverThreaded.cpp | 9 +++++ .../MemoryCard/MemoryCardDriverThreaded.h | 1 + .../MemoryCardDriverThreaded_Linux.cpp | 37 +++++++++---------- .../MemoryCardDriverThreaded_Linux.h | 1 + 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp index 20adf1da42..42747cc592 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp @@ -79,11 +79,20 @@ void MemoryCardDriverThreaded::MountThreadMain() while( !m_bShutdownNextUpdate ) { + if( !this->MountThreadWaitForUpdate() ) + continue; + LockMut( m_mutexPause ); // wait until we're unpaused this->MountThreadDoOneUpdate(); } } +bool MemoryCardDriverThreaded::MountThreadWaitForUpdate() +{ + usleep( 100000 ); + return true; +} + bool MemoryCardDriverThreaded::StorageDevicesChanged() { CHECKPOINT; diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h index dad7b6a2b6..61848c1acf 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h @@ -33,6 +33,7 @@ protected: void StartThread(); // call this in the derived constructor to start the mounting thread void StopThread(); // call this in the derived desstructor to stop the mounting thread virtual void MountThreadDoOneUpdate() = 0; // this will get called as fast as possible + virtual bool MountThreadWaitForUpdate(); virtual void Mount( UsbStorageDevice* pDevice, CString sMountPoint ) = 0; bool ShouldDoOsMount() { return m_MountThreadState==detect_and_mount; } diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp index fc64498e63..e07b647dc0 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp @@ -187,32 +187,29 @@ bool UsbStorageDevicesChanged() return bChanged; } -void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate() +/* Return true if MountThreadDoOneUpdate should be called. */ +bool MemoryCardDriverThreaded_Linux::MountThreadWaitForUpdate() { - bool bNeedToDoAnyMounts = false; + /* Check if any devices need a write test. */ for( unsigned i=0; i m_vDevicesLastSeen; };