Fix unnecessary remounts of cards that weren't changed since last update.\nDon't do OS mounts or unmounts while after cards are locked. It can cause skips.

This commit is contained in:
Chris Danford
2004-08-08 18:44:41 +00:00
parent fc4251f798
commit 551800cceb
7 changed files with 59 additions and 24 deletions
+5
View File
@@ -148,6 +148,11 @@ void MemoryCardManager::LockCards( bool bLock )
FOREACH_PlayerNumber( p )
m_bTooLate[p] = false;
}
if( m_bCardsLocked )
m_pDriver->DontDoOsMount();
else
m_pDriver->DoOsMount();
}
void MemoryCardManager::AssignUnassignedCards()
@@ -4,6 +4,21 @@
#include "arch/arch_platform.h"
bool UsbStorageDevice::operator==(const UsbStorageDevice& other) const
{
// LOG->Trace( "Comparing %d %d %d %s %s to %d %d %d %s %s",
// iBus, iPort, iLevel, sName.c_str(), sOsMountDir.c_str(),
// other.iBus, other.iPort, other.iLevel, other.sName.c_str(), other.sOsMountDir.c_str() );
#define COMPARE(x) if( x != other.x ) return false;
COMPARE( iBus );
COMPARE( iPort );
COMPARE( iLevel );
COMPARE( sOsMountDir );
return true;
#undef COMPARE
}
MemoryCardDriver *MakeMemoryCardDriver()
{
if( !PREFSMAN->m_bMemoryCards )
@@ -29,17 +29,7 @@ struct UsbStorageDevice
bool IsBlank() { return sOsMountDir.empty(); }
bool operator==(const UsbStorageDevice& other) const
{
#define COMPARE(x) if( x != other.x ) return false;
COMPARE( iBus );
COMPARE( iPort );
COMPARE( iLevel );
COMPARE( sName );
COMPARE( sOsMountDir );
return true;
#undef COMPARE
}
bool operator==(const UsbStorageDevice& other) const;
bool operator!=(const UsbStorageDevice& other) const
{
return !operator==(other);
@@ -59,6 +49,8 @@ public:
virtual void ResetUsbStorage() = 0;
virtual void PauseMountingThread() = 0;
virtual void UnPauseMountingThread() = 0;
virtual void DoOsMount() = 0;
virtual void DontDoOsMount() = 0;
};
MemoryCardDriver *MakeMemoryCardDriver();
@@ -26,6 +26,7 @@ MemoryCardDriverThreaded::MemoryCardDriverThreaded() :
{
m_bShutdownNextUpdate = false;
m_bStorageDevicesChanged = false;
m_bDoOsMount = true;
}
void MemoryCardDriverThreaded::StartThread()
@@ -61,6 +62,16 @@ void MemoryCardDriverThreaded::UnPauseMountingThread()
m_mutexPause.Unlock();
}
void MemoryCardDriverThreaded::DoOsMount()
{
m_bDoOsMount = true;
}
void MemoryCardDriverThreaded::DontDoOsMount()
{
m_bDoOsMount = false;
}
int MemoryCardDriverThreaded::MountThread_Start( void *p )
{
((MemoryCardDriverThreaded*)p)->MountThreadMain();
@@ -27,6 +27,8 @@ public:
virtual bool MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint );
virtual void PauseMountingThread();
virtual void UnPauseMountingThread();
virtual void DoOsMount();
virtual void DontDoOsMount();
private:
static int MountThread_Start( void *p );
@@ -40,11 +42,16 @@ private:
// will temporarily halt.
RageMutex m_mutexPause;
// If true, detect and report changes in connected devices, but don't don't
// do the OS mount or unmount.
bool m_bDoOsMount;
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 void Mount( UsbStorageDevice* pDevice, CString sMountPoint ) = 0;
bool ShouldDoOsMount() { return m_bDoOsMount; }
vector<UsbStorageDeviceEx> m_vStorageDevices;
bool m_bStorageDevicesChanged;
@@ -221,7 +221,7 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate()
UsbStorageDeviceEx &old = vOld[i];
if( find(vNew.begin(),vNew.end(),old) == vNew.end() )// didn't find
{
LOG->Trace( ssprintf("Disconnected bus %d port %d level %d path %s", old.iBus, old.iPort, old.iLevel, old.sOsMountDir.c_str()) );
LOG->Trace( "Disconnected bus %d port %d level %d path %s", old.iBus, old.iPort, old.iLevel, old.sOsMountDir.c_str() );
vDisconnects.push_back( &old );
}
}
@@ -233,24 +233,26 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate()
UsbStorageDeviceEx &newd = vNew[i];
if( find(vOld.begin(),vOld.end(),newd) == vOld.end() )// didn't find
{
LOG->Trace( ssprintf("Connected bus %d port %d level %d path %s", newd.iBus, newd.iPort, newd.iLevel, newd.sOsMountDir.c_str()) );
LOG->Trace( "Connected bus %d port %d level %d path %s", newd.iBus, newd.iPort, newd.iLevel, newd.sOsMountDir.c_str() );
vConnects.push_back( &newd );
}
}
// unmount all disconnects
for( unsigned i=0; i<vDisconnects.size(); i++ )
{
if( ShouldDoOsMount() )
{
for( unsigned i=0; i<vDisconnects.size(); i++ )
{
UsbStorageDeviceEx &d = *vDisconnects[i];
CString sCommand = "umount " + d.sOsMountDir;
LOG->Trace( "unmount disconnects %i/%i (%s)", i, vDisconnects.size(), sCommand.c_str() );
ExecuteCommand( sCommand );
LOG->Trace( "unmount disconnects %i/%i done", i, vDisconnects.size() );
}
// mount all connects
for( unsigned i=0; i<vConnects.size(); i++ )
{
}
// mount all connects
for( unsigned i=0; i<vConnects.size(); i++ )
{
UsbStorageDeviceEx &d = *vConnects[i];
CString sCommand;
@@ -263,9 +265,9 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate()
LOG->Trace( "unmount old connect %i/%i done", i, vConnects.size() );
sCommand = "mount " + d.sOsMountDir;
LOG->Trace( "unmount new connect %i/%i (%s)", i, vConnects.size(), sCommand.c_str() );
LOG->Trace( "mount new connect %i/%i (%s)", i, vConnects.size(), sCommand.c_str() );
bool bMountedSuccessfully = ExecuteCommand( sCommand );
LOG->Trace( "unmount new connect %i/%i done", i, vConnects.size() );
LOG->Trace( "mount new connect %i/%i done", i, vConnects.size() );
d.bWriteTestSucceeded = bMountedSuccessfully && TestWrite( d.sOsMountDir );
@@ -278,8 +280,9 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate()
d.sName = profile.GetDisplayName();
LOG->Trace( "write test %s", d.bWriteTestSucceeded ? "succeeded" : "failed" );
}
}
}
if( !vDisconnects.empty() || !vConnects.empty() )
{
LockMut( m_mutexStorageDevices );
@@ -15,6 +15,8 @@ public:
virtual void ResetUsbStorage() {}
virtual void PauseMountingThread() {}
virtual void UnPauseMountingThread() {}
virtual void DoOsMount() {}
virtual void DontDoOsMount() {}
};
#endif