Changed: Replaced some mutexes.

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 13 years ago
parent 8bdfa294eb
commit 47f4d0b7e9

@ -133,7 +133,7 @@ bool CDatabaseStatus::getFileStatus(CFileStatus &fileStatus, const std::string &
bool seemsValid = false; bool seemsValid = false;
std::string stdPath = unMacroPath(filePath); std::string stdPath = unMacroPath(filePath);
std::string statusPath = getStatusFilePath(filePath); std::string statusPath = getStatusFilePath(filePath);
m_StatusMutex.enterReader(); m_StatusMutex.lock_shared();
if (CFile::fileExists(statusPath)) if (CFile::fileExists(statusPath))
{ {
CIFile ifs(statusPath, false); CIFile ifs(statusPath, false);
@ -153,7 +153,7 @@ bool CDatabaseStatus::getFileStatus(CFileStatus &fileStatus, const std::string &
fileStatus.LastUpdate = 0; fileStatus.LastUpdate = 0;
fileStatus.CRC32 = 0; fileStatus.CRC32 = 0;
} }
m_StatusMutex.leaveReader(); m_StatusMutex.unlock_shared();
return seemsValid; return seemsValid;
} }
@ -167,7 +167,7 @@ public:
TFileStatusCallback Callback; TFileStatusCallback Callback;
std::string FilePath; // Standardized! std::string FilePath; // Standardized!
CReaderWriter *StatusMutex; boost::shared_mutex *StatusMutex;
virtual void run() virtual void run()
{ {
@ -178,7 +178,7 @@ public:
uint32 time = CTime::getSecondsSince1970(); uint32 time = CTime::getSecondsSince1970();
uint32 fmdt = CFile::getFileModificationDate(FilePath); uint32 fmdt = CFile::getFileModificationDate(FilePath);
std::string statusPath = getStatusFilePath(FilePath); // g_PipelineDirectory + PIPELINE_DATABASE_STATUS_SUBDIR + dropDatabaseDirectory(FilePath) + ".status"; std::string statusPath = getStatusFilePath(FilePath); // g_PipelineDirectory + PIPELINE_DATABASE_STATUS_SUBDIR + dropDatabaseDirectory(FilePath) + ".status";
StatusMutex->enterReader(); StatusMutex->lock_shared();
if (CFile::fileExists(statusPath)) if (CFile::fileExists(statusPath))
{ {
CIFile ifs(statusPath, false); CIFile ifs(statusPath, false);
@ -191,7 +191,7 @@ public:
fs.LastChangedReference = 0; fs.LastChangedReference = 0;
fs.LastFileSizeReference = ~0; fs.LastFileSizeReference = ~0;
} }
StatusMutex->leaveReader(); StatusMutex->unlock_shared();
if (fs.LastChangedReference == fmdt && fs.LastFileSizeReference == CFile::getFileSize(FilePath)) if (fs.LastChangedReference == fmdt && fs.LastFileSizeReference == CFile::getFileSize(FilePath))
{ {
nlinfo("Skipping already updated status, may have been queued twice (%s)", FilePath.c_str()); nlinfo("Skipping already updated status, may have been queued twice (%s)", FilePath.c_str());
@ -228,14 +228,14 @@ public:
fs.LastFileSizeReference = fisz; fs.LastFileSizeReference = fisz;
} }
StatusMutex->enterWriter(); StatusMutex->lock();
{ {
COFile ofs(statusPath, false, false, true); COFile ofs(statusPath, false, false, true);
fs.serial(ofs); fs.serial(ofs);
ofs.flush(); ofs.flush();
ofs.close(); ofs.close();
} }
StatusMutex->leaveWriter(); StatusMutex->unlock();
} }
Callback(FilePath, fs, true); Callback(FilePath, fs, true);
} }

@ -32,9 +32,10 @@
// STL includes // STL includes
#include <string> #include <string>
#include <vector> #include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/thread/shared_mutex.hpp>
// NeL includes // NeL includes
#include <nel/misc/mutex.h>
#include <nel/misc/reader_writer.h> #include <nel/misc/reader_writer.h>
#include <nel/misc/stream.h> #include <nel/misc/stream.h>
@ -95,8 +96,8 @@ typedef CCallback<void, const std::string &/*filePath*/, const CFileStatus &/*fi
class CDatabaseStatus class CDatabaseStatus
{ {
protected: protected:
mutable NLMISC::CReaderWriter m_StatusMutex; mutable boost::shared_mutex m_StatusMutex;
mutable NLMISC::CMutex m_ErrorMutex; mutable boost::mutex m_ErrorMutex;
public: public:
CDatabaseStatus(); CDatabaseStatus();

Loading…
Cancel
Save