fix ZIP thread-safety?

This commit is contained in:
Glenn Maynard
2005-02-24 06:07:49 +00:00
parent fbf7bc4f26
commit a9c73de5b6
2 changed files with 12 additions and 2 deletions
+7 -2
View File
@@ -52,7 +52,8 @@ struct end_central_dir_record
#define DEFLATED 8 #define DEFLATED 8
RageFileDriverZip::RageFileDriverZip( CString path ): RageFileDriverZip::RageFileDriverZip( CString path ):
RageFileDriver( new NullFilenameDB ) RageFileDriver( new NullFilenameDB ),
m_Mutex( ssprintf("RageFileDriverZip(%s)", path.c_str()) )
{ {
if( !zip.Open(path) ) if( !zip.Open(path) )
RageException::Throw( "Couldn't open %s: %s", path.c_str(), zip.GetError().c_str() ); 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; return NULL;
} }
m_Mutex.Lock();
/* If we havn't figured out the offset to the real data yet, do so now. */ /* If we havn't figured out the offset to the real data yet, do so now. */
if( info->data_offset == -1 ) 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; 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 ); RageFileDriverSlice *pFile = new RageFileDriverSlice( zip.Copy(), info->data_offset, info->compr_size );
pFile->DeleteFileWhenFinished(); pFile->DeleteFileWhenFinished();
+5
View File
@@ -4,6 +4,7 @@
#define RAGE_FILE_DRIVER_ZIP_H #define RAGE_FILE_DRIVER_ZIP_H
#include "RageFileDriver.h" #include "RageFileDriver.h"
#include "RageThreads.h"
struct FileInfo; struct FileInfo;
struct end_central_dir_record; struct end_central_dir_record;
@@ -20,6 +21,10 @@ private:
RageFile zip; RageFile zip;
vector<FileInfo *> Files; vector<FileInfo *> Files;
/* Open() must be threadsafe. Mutex access to "zip", since we seek
* around in it when reading files. */
RageMutex m_Mutex;
void ParseZipfile(); void ParseZipfile();
static void ReadEndCentralRecord( RageFile &zip, end_central_dir_record &ec ); static void ReadEndCentralRecord( RageFile &zip, end_central_dir_record &ec );
static int ProcessCdirFileHdr( RageFile &zip, FileInfo &info ); static int ProcessCdirFileHdr( RageFile &zip, FileInfo &info );