From bc39cb5079c0fa9d8df97cc3dd6fb9932c2f8ce5 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 9 Oct 2004 08:16:48 +0000 Subject: [PATCH] serialize all memory card operations since mount operations hang if we're doing lsusb or reading USB mass storage descriptors in another thread --- stepmania/src/GameState.cpp | 13 +++++++++---- stepmania/src/MemoryCardManager.cpp | 22 ++++++++++++---------- stepmania/src/MemoryCardManager.h | 6 +++--- stepmania/src/ProfileManager.cpp | 9 --------- stepmania/src/ScreenEvaluation.cpp | 2 ++ 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index ea7e8315a8..f55182c83c 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -232,7 +232,8 @@ void GameState::PlayersFinalized() m_bPlayersFinalized = true; - MEMCARDMAN->LockCards( true ); + MEMCARDMAN->PauseMountingThread(); + MEMCARDMAN->LockCards( true ); // this does a mount // apply saved default modifiers if any FOREACH_HumanPlayer( pn ) @@ -272,6 +273,7 @@ void GameState::PlayersFinalized() if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) MEMCARDMAN->UnmountAllUsedCards(); + MEMCARDMAN->UnPauseMountingThread(); } /* 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 ) - MEMCARDMAN->UnmountAllUsedCards(); - + MEMCARDMAN->MountAllUsedCards(); BOOKKEEPER->WriteToDisk(); PROFILEMAN->SaveAllProfiles(); @@ -359,11 +360,15 @@ void GameState::EndGame() PROFILEMAN->UnloadProfile( pn ); } + if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) + MEMCARDMAN->UnmountAllUsedCards(); + // Reset the USB storage device numbers -after- saving CHECKPOINT; MEMCARDMAN->FlushAndReset(); CHECKPOINT; + SONGMAN->FreeAllLoadedFromProfiles(); // make sure we don't execute EndGame twice. diff --git a/stepmania/src/MemoryCardManager.cpp b/stepmania/src/MemoryCardManager.cpp index 7055829037..4949fedf70 100644 --- a/stepmania/src/MemoryCardManager.cpp +++ b/stepmania/src/MemoryCardManager.cpp @@ -215,16 +215,16 @@ void MemoryCardManager::LockCards( bool bLock ) m_pDriver->MountAndTestWrite(&m_Device[p], MEM_CARD_MOUNT_POINT[p]); } } - - if( !bWasLocked && bLock ) - m_pDriver->SetMountThreadState( MemoryCardDriver::detect_and_dont_mount ); - else + + if( !bLock ) + { m_pDriver->SetMountThreadState( MemoryCardDriver::detect_and_mount ); + } } void MemoryCardManager::TryMountAllCards() { - FOREACH_PlayerNumber( p ) + FOREACH_EnabledPlayer( p ) { if( m_Device[p].IsBlank() ) // they don't have an assigned card continue; @@ -235,12 +235,12 @@ void MemoryCardManager::TryMountAllCards() void MemoryCardManager::MountAllUsedCards() { - FOREACH_PlayerNumber( p ) + FOREACH_EnabledPlayer( p ) { if( m_Device[p].IsBlank() ) // they don't have an assigned card continue; - if( m_bTooLate[p] || !m_Device[p].bWriteTestSucceeded ) + if( m_bTooLate[p] || !m_Device[p].bWriteTestSucceeded || !PROFILEMAN->ProfileWasLoadedFromMemoryCard(p) ) continue; m_pDriver->MountAndTestWrite(&m_Device[p], MEM_CARD_MOUNT_POINT[p]); @@ -249,12 +249,12 @@ void MemoryCardManager::MountAllUsedCards() void MemoryCardManager::UnmountAllUsedCards() { - FOREACH_PlayerNumber( p ) + FOREACH_EnabledPlayer( p ) { if( m_Device[p].IsBlank() ) // they don't have an assigned card continue; - if( m_bTooLate[p] || !m_Device[p].bWriteTestSucceeded ) + if( m_bTooLate[p] || !m_Device[p].bWriteTestSucceeded || !PROFILEMAN->ProfileWasLoadedFromMemoryCard(p) ) continue; m_pDriver->Unmount(&m_Device[p], MEM_CARD_MOUNT_POINT[p]); @@ -317,9 +317,11 @@ void MemoryCardManager::UnPauseMountingThread() bool IsAnyPlayerUsingMemoryCard() { FOREACH_HumanPlayer( pn ) + { if( MEMCARDMAN->GetCardState(pn) == MEMORY_CARD_STATE_READY ) return true; - return false; + } + return false; } #include "LuaFunctions.h" diff --git a/stepmania/src/MemoryCardManager.h b/stepmania/src/MemoryCardManager.h index facbdd1772..b77a78d72e 100644 --- a/stepmania/src/MemoryCardManager.h +++ b/stepmania/src/MemoryCardManager.h @@ -33,10 +33,10 @@ public: void MountCard( PlayerNumber pn ); void UnmountCard( PlayerNumber pn ); - void PauseMountingThread(); // call this before reading or writing to memory card - void UnPauseMountingThread(); // call this when done reading or writing to memory card + void PauseMountingThread(); // call this before mouting, 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; diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index 44030a3d27..ebedc49765 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -139,12 +139,9 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) sDir += PREFSMAN->m_sMemoryCardProfileSubdir; sDir += '/'; - MEMCARDMAN->PauseMountingThread(); bool bSuccess; 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. } @@ -180,14 +177,8 @@ bool ProfileManager::SaveProfile( PlayerNumber pn ) const if( m_sProfileDir[pn].empty() ) return false; - if( ProfileWasLoadedFromMemoryCard(pn) ) - MEMCARDMAN->PauseMountingThread(); - bool b = m_Profile[pn].SaveAllToDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData ); - if( ProfileWasLoadedFromMemoryCard(pn) ) - MEMCARDMAN->UnPauseMountingThread(); - return b; } diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index e54820c0de..4111048352 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -1353,6 +1353,7 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t if( !m_bSavedScreenshot[pn] && // only allow one screenshot PROFILEMAN->IsUsingProfile(pn) ) { + MEMCARDMAN->PauseMountingThread(); if( PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn) && PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) MEMCARDMAN->MountCard( pn ); @@ -1364,6 +1365,7 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t if( PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn) && PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) MEMCARDMAN->UnmountCard( pn ); + MEMCARDMAN->UnPauseMountingThread(); if( !sFileName.empty() ) {