From 4c8c5bea37436f29361563d380ead60717c09fa3 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 22 May 2005 01:36:08 +0000 Subject: [PATCH] Add variable timeouts. After mounting or unmounting a filesystem, flush cache, so we don't keep stale cache around. RageFileDriverDirect::Remount could (and should) flush its own cache when changing root (since the cache represents the old root). However, calling Remount doesn't indicate that the filesystem has actually changed, so if the root isn't actually changing (Remount("/mnt") on a filesystem already pointing to /mnt), the driver can't be expected to flush. (Remount also currently doesn't go through Timeout, and we need to flush on unmount, too.) So, take the cheap way out and just flush through FILEMAN. --- stepmania/src/MemoryCardManager.cpp | 21 +++++++++++++++------ stepmania/src/MemoryCardManager.h | 4 ++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/stepmania/src/MemoryCardManager.cpp b/stepmania/src/MemoryCardManager.cpp index c1b81b1af3..f9a7f7fe8f 100644 --- a/stepmania/src/MemoryCardManager.cpp +++ b/stepmania/src/MemoryCardManager.cpp @@ -568,7 +568,7 @@ void MemoryCardManager::UnlockCards() } /* Called just before reading or writing to the memory card. Should block. */ -void MemoryCardManager::MountCard( PlayerNumber pn ) +void MemoryCardManager::MountCard( PlayerNumber pn, int iTimeout ) { LOG->Trace( "MemoryCardManager::MountCard(%i)", pn ); if( GetCardState(pn) != MEMORY_CARD_STATE_READY ) @@ -583,7 +583,7 @@ void MemoryCardManager::MountCard( PlayerNumber pn ) if( bStartingMemoryCardAccess ) { /* We're starting to do stuff to the memory cards. */ - this->PauseMountingThread(); + this->PauseMountingThread( iTimeout ); } if( !g_pWorker->Mount( &m_Device[pn] ) ) @@ -609,13 +609,18 @@ void MemoryCardManager::MountCard( PlayerNumber pn ) /* We just created a worker thread. Reset the timeout, or those threads * won't time out. This is a hack; we should really be creating the timeout * driver on startup. */ - this->PauseMountingThread(); + this->PauseMountingThread( iTimeout ); } else { /* It's already mounted. We don't want to unmount the timeout FS. Instead, just * move the target. */ pDriver->Remount( m_Device[pn].sOsMountDir ); + + /* Flush mountpoints pointing to what we've mounted. */ + FILEMAN->FlushDirCache( MEM_CARD_MOUNT_POINT[pn] ); + FILEMAN->FlushDirCache( MEM_CARD_MOUNT_POINT_INTERNAL[pn] ); + FILEMAN->ReleaseFileDriver( pDriver ); } } @@ -634,6 +639,10 @@ void MemoryCardManager::UnmountCard( PlayerNumber pn ) /* Leave our own filesystem drivers mounted. Unmount the kernel mount. */ g_pWorker->Unmount( &m_Device[pn] ); + /* Flush mountpoints pointing to what we've unmounted. */ + FILEMAN->FlushDirCache( MEM_CARD_MOUNT_POINT[pn] ); + FILEMAN->FlushDirCache( MEM_CARD_MOUNT_POINT_INTERNAL[pn] ); + m_bMounted[pn] = false; /* Unpause the mounting thread when we unmount the last drive. */ @@ -684,13 +693,13 @@ CString MemoryCardManager::GetName( PlayerNumber pn ) const return m_Device[pn].sName; } -void MemoryCardManager::PauseMountingThread() +void MemoryCardManager::PauseMountingThread( int iTimeout ) { g_pWorker->SetMountThreadState( ThreadedMemoryCardWorker::paused ); /* Start the timeout period. */ - g_pWorker->SetTimeout( 10 ); - RageFileDriverTimeout::SetTimeout( 10 ); + g_pWorker->SetTimeout( iTimeout ); + RageFileDriverTimeout::SetTimeout( iTimeout ); } void MemoryCardManager::UnPauseMountingThread() diff --git a/stepmania/src/MemoryCardManager.h b/stepmania/src/MemoryCardManager.h index 99efa47794..b182530e32 100644 --- a/stepmania/src/MemoryCardManager.h +++ b/stepmania/src/MemoryCardManager.h @@ -22,11 +22,11 @@ public: void LockCards(); // prevent removing or changing of memory cards void UnlockCards(); - void MountCard( PlayerNumber pn ); + void MountCard( PlayerNumber pn, int iTimeout = 10 ); void UnmountCard( PlayerNumber pn ); /* When paused, no changes in memory card state will be noticed until unpaused. */ - void PauseMountingThread(); + void PauseMountingThread( int iTimeout = 10 ); void UnPauseMountingThread(); void FlushAndReset(); // force all files to be flushed to mounted memory cards