diff --git a/player/common/storage/FileCacheImpl.cpp b/player/common/storage/FileCacheImpl.cpp index 78fc22036..44ca3f772 100644 --- a/player/common/storage/FileCacheImpl.cpp +++ b/player/common/storage/FileCacheImpl.cpp @@ -145,9 +145,12 @@ void FileCacheImpl::addToCache(const std::string& filename, const Md5Hash& hash, node.put(Md5Attr, hash); node.put(ValidAttr, hash == target); + /* critical section, access and modify file cache buffer */ + fileCacheMutex_.lock(); fileCache_.put_child(fullPath(filename), node); saveFileHashes(cacheFile_); + fileCacheMutex_.unlock(); } void FileCacheImpl::addToCache(const std::string& filename, const Md5Hash& hash, const DateTime& lastUpdate) @@ -157,9 +160,12 @@ void FileCacheImpl::addToCache(const std::string& filename, const Md5Hash& hash, node.put(LastUpdateAttr, lastUpdate.timestamp()); node.put(ValidAttr, true); + /* critical section, access and modify file cache buffer */ + fileCacheMutex_.lock(); fileCache_.put_child(fullPath(filename), node); saveFileHashes(cacheFile_); + fileCacheMutex_.unlock(); } void FileCacheImpl::loadFileHashes(const FilePath& path) diff --git a/player/common/storage/FileCacheImpl.hpp b/player/common/storage/FileCacheImpl.hpp index 2f269fafc..8509acd33 100644 --- a/player/common/storage/FileCacheImpl.hpp +++ b/player/common/storage/FileCacheImpl.hpp @@ -4,6 +4,7 @@ #include "common/storage/FileCache.hpp" #include +#include class FileCacheImpl : public FileCache, public XmlDefaultFileHandler, private boost::noncopyable { @@ -31,6 +32,7 @@ class FileCacheImpl : public FileCache, public XmlDefaultFileHandler, private bo void saveFileHashes(const FilePath& path); private: + boost::mutex fileCacheMutex_; XmlNode fileCache_; FilePath cacheFile_; };