From a9c73de5b63dffa88a9e9a749add3fbc5457e535 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 24 Feb 2005 06:07:49 +0000 Subject: [PATCH] fix ZIP thread-safety? --- stepmania/src/RageFileDriverZip.cpp | 9 +++++++-- stepmania/src/RageFileDriverZip.h | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/stepmania/src/RageFileDriverZip.cpp b/stepmania/src/RageFileDriverZip.cpp index a04ed3d600..db024cfe26 100644 --- a/stepmania/src/RageFileDriverZip.cpp +++ b/stepmania/src/RageFileDriverZip.cpp @@ -52,7 +52,8 @@ struct end_central_dir_record #define DEFLATED 8 RageFileDriverZip::RageFileDriverZip( CString path ): - RageFileDriver( new NullFilenameDB ) + RageFileDriver( new NullFilenameDB ), + m_Mutex( ssprintf("RageFileDriverZip(%s)", path.c_str()) ) { if( !zip.Open(path) ) RageException::Throw( "Couldn't open %s: %s", path.c_str(), zip.GetError().c_str() ); @@ -333,6 +334,8 @@ RageFileBasic *RageFileDriverZip::Open( const CString &path, int mode, int &err return NULL; } + m_Mutex.Lock(); + /* If we havn't figured out the offset to the real data yet, do so now. */ if( info->data_offset == -1 ) { @@ -364,7 +367,9 @@ RageFileBasic *RageFileDriverZip::Open( const CString &path, int mode, int &err info->data_offset = zip.Tell() + filename_length + extra_field_length; } - zip.Seek( info->data_offset ); + /* We won't do any further access to zip, except to copy it (which is + * threadsafe), so we can unlock now. */ + m_Mutex.Unlock(); RageFileDriverSlice *pFile = new RageFileDriverSlice( zip.Copy(), info->data_offset, info->compr_size ); pFile->DeleteFileWhenFinished(); diff --git a/stepmania/src/RageFileDriverZip.h b/stepmania/src/RageFileDriverZip.h index ac00d9a2d7..b1ca96e632 100644 --- a/stepmania/src/RageFileDriverZip.h +++ b/stepmania/src/RageFileDriverZip.h @@ -4,6 +4,7 @@ #define RAGE_FILE_DRIVER_ZIP_H #include "RageFileDriver.h" +#include "RageThreads.h" struct FileInfo; struct end_central_dir_record; @@ -20,6 +21,10 @@ private: RageFile zip; vector Files; + /* Open() must be threadsafe. Mutex access to "zip", since we seek + * around in it when reading files. */ + RageMutex m_Mutex; + void ParseZipfile(); static void ReadEndCentralRecord( RageFile &zip, end_central_dir_record &ec ); static int ProcessCdirFileHdr( RageFile &zip, FileInfo &info );