serialize all memory card operations since mount operations hang if we're doing lsusb or reading USB mass storage descriptors in another thread

This commit is contained in:
Chris Danford
2004-10-09 08:16:48 +00:00
parent f8a8294588
commit bc39cb5079
5 changed files with 26 additions and 26 deletions
+9 -4
View File
@@ -232,7 +232,8 @@ void GameState::PlayersFinalized()
m_bPlayersFinalized = true; m_bPlayersFinalized = true;
MEMCARDMAN->LockCards( true ); MEMCARDMAN->PauseMountingThread();
MEMCARDMAN->LockCards( true ); // this does a mount
// apply saved default modifiers if any // apply saved default modifiers if any
FOREACH_HumanPlayer( pn ) FOREACH_HumanPlayer( pn )
@@ -272,6 +273,7 @@ void GameState::PlayersFinalized()
if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary )
MEMCARDMAN->UnmountAllUsedCards(); MEMCARDMAN->UnmountAllUsedCards();
MEMCARDMAN->UnPauseMountingThread();
} }
/* This data is added to each player profile, and to the machine profile per-player. */ /* This data is added to each player profile, and to the machine profile per-player. */
@@ -343,10 +345,9 @@ void GameState::EndGame()
} }
} }
MEMCARDMAN->PauseMountingThread();
if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary )
MEMCARDMAN->UnmountAllUsedCards(); MEMCARDMAN->MountAllUsedCards();
BOOKKEEPER->WriteToDisk(); BOOKKEEPER->WriteToDisk();
PROFILEMAN->SaveAllProfiles(); PROFILEMAN->SaveAllProfiles();
@@ -359,11 +360,15 @@ void GameState::EndGame()
PROFILEMAN->UnloadProfile( pn ); PROFILEMAN->UnloadProfile( pn );
} }
if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary )
MEMCARDMAN->UnmountAllUsedCards();
// Reset the USB storage device numbers -after- saving // Reset the USB storage device numbers -after- saving
CHECKPOINT; CHECKPOINT;
MEMCARDMAN->FlushAndReset(); MEMCARDMAN->FlushAndReset();
CHECKPOINT; CHECKPOINT;
SONGMAN->FreeAllLoadedFromProfiles(); SONGMAN->FreeAllLoadedFromProfiles();
// make sure we don't execute EndGame twice. // make sure we don't execute EndGame twice.
+10 -8
View File
@@ -216,15 +216,15 @@ void MemoryCardManager::LockCards( bool bLock )
} }
} }
if( !bWasLocked && bLock ) if( !bLock )
m_pDriver->SetMountThreadState( MemoryCardDriver::detect_and_dont_mount ); {
else
m_pDriver->SetMountThreadState( MemoryCardDriver::detect_and_mount ); m_pDriver->SetMountThreadState( MemoryCardDriver::detect_and_mount );
} }
}
void MemoryCardManager::TryMountAllCards() void MemoryCardManager::TryMountAllCards()
{ {
FOREACH_PlayerNumber( p ) FOREACH_EnabledPlayer( p )
{ {
if( m_Device[p].IsBlank() ) // they don't have an assigned card if( m_Device[p].IsBlank() ) // they don't have an assigned card
continue; continue;
@@ -235,12 +235,12 @@ void MemoryCardManager::TryMountAllCards()
void MemoryCardManager::MountAllUsedCards() void MemoryCardManager::MountAllUsedCards()
{ {
FOREACH_PlayerNumber( p ) FOREACH_EnabledPlayer( p )
{ {
if( m_Device[p].IsBlank() ) // they don't have an assigned card if( m_Device[p].IsBlank() ) // they don't have an assigned card
continue; continue;
if( m_bTooLate[p] || !m_Device[p].bWriteTestSucceeded ) if( m_bTooLate[p] || !m_Device[p].bWriteTestSucceeded || !PROFILEMAN->ProfileWasLoadedFromMemoryCard(p) )
continue; continue;
m_pDriver->MountAndTestWrite(&m_Device[p], MEM_CARD_MOUNT_POINT[p]); m_pDriver->MountAndTestWrite(&m_Device[p], MEM_CARD_MOUNT_POINT[p]);
@@ -249,12 +249,12 @@ void MemoryCardManager::MountAllUsedCards()
void MemoryCardManager::UnmountAllUsedCards() void MemoryCardManager::UnmountAllUsedCards()
{ {
FOREACH_PlayerNumber( p ) FOREACH_EnabledPlayer( p )
{ {
if( m_Device[p].IsBlank() ) // they don't have an assigned card if( m_Device[p].IsBlank() ) // they don't have an assigned card
continue; continue;
if( m_bTooLate[p] || !m_Device[p].bWriteTestSucceeded ) if( m_bTooLate[p] || !m_Device[p].bWriteTestSucceeded || !PROFILEMAN->ProfileWasLoadedFromMemoryCard(p) )
continue; continue;
m_pDriver->Unmount(&m_Device[p], MEM_CARD_MOUNT_POINT[p]); m_pDriver->Unmount(&m_Device[p], MEM_CARD_MOUNT_POINT[p]);
@@ -317,8 +317,10 @@ void MemoryCardManager::UnPauseMountingThread()
bool IsAnyPlayerUsingMemoryCard() bool IsAnyPlayerUsingMemoryCard()
{ {
FOREACH_HumanPlayer( pn ) FOREACH_HumanPlayer( pn )
{
if( MEMCARDMAN->GetCardState(pn) == MEMORY_CARD_STATE_READY ) if( MEMCARDMAN->GetCardState(pn) == MEMORY_CARD_STATE_READY )
return true; return true;
}
return false; return false;
} }
+3 -3
View File
@@ -33,10 +33,10 @@ public:
void MountCard( PlayerNumber pn ); void MountCard( PlayerNumber pn );
void UnmountCard( PlayerNumber pn ); void UnmountCard( PlayerNumber pn );
void PauseMountingThread(); // call this before reading or writing to memory card void PauseMountingThread(); // call this before mouting, reading, or writing to memory card
void UnPauseMountingThread(); // call this when done reading or writing to memory card void UnPauseMountingThread(); // call this when done mouting, reading, or writing to memory card
void FlushAndReset(); // force all files to be written to mounted memory cards void FlushAndReset(); // force all files to be flushed to mounted memory cards
bool PathIsMemCard( CString sDir ) const; bool PathIsMemCard( CString sDir ) const;
-9
View File
@@ -139,12 +139,9 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn )
sDir += PREFSMAN->m_sMemoryCardProfileSubdir; sDir += PREFSMAN->m_sMemoryCardProfileSubdir;
sDir += '/'; sDir += '/';
MEMCARDMAN->PauseMountingThread();
bool bSuccess; bool bSuccess;
bSuccess = LoadProfile( pn, sDir, true ); bSuccess = LoadProfile( pn, sDir, true );
MEMCARDMAN->UnPauseMountingThread();
return true; // If a card is inserted, we want to use the memory card to save - even if the Profile load failed. return true; // If a card is inserted, we want to use the memory card to save - even if the Profile load failed.
} }
@@ -180,14 +177,8 @@ bool ProfileManager::SaveProfile( PlayerNumber pn ) const
if( m_sProfileDir[pn].empty() ) if( m_sProfileDir[pn].empty() )
return false; return false;
if( ProfileWasLoadedFromMemoryCard(pn) )
MEMCARDMAN->PauseMountingThread();
bool b = m_Profile[pn].SaveAllToDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData ); bool b = m_Profile[pn].SaveAllToDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData );
if( ProfileWasLoadedFromMemoryCard(pn) )
MEMCARDMAN->UnPauseMountingThread();
return b; return b;
} }
+2
View File
@@ -1353,6 +1353,7 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t
if( !m_bSavedScreenshot[pn] && // only allow one screenshot if( !m_bSavedScreenshot[pn] && // only allow one screenshot
PROFILEMAN->IsUsingProfile(pn) ) PROFILEMAN->IsUsingProfile(pn) )
{ {
MEMCARDMAN->PauseMountingThread();
if( PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn) && PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) if( PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn) && PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary )
MEMCARDMAN->MountCard( pn ); MEMCARDMAN->MountCard( pn );
@@ -1364,6 +1365,7 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t
if( PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn) && PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) if( PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn) && PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary )
MEMCARDMAN->UnmountCard( pn ); MEMCARDMAN->UnmountCard( pn );
MEMCARDMAN->UnPauseMountingThread();
if( !sFileName.empty() ) if( !sFileName.empty() )
{ {