Get rid of download_mutex

This commit is contained in:
kssenii 2023-02-16 14:33:23 +01:00
parent e182f163f8
commit d14f86cfe8
2 changed files with 1 additions and 15 deletions

View File

@ -132,10 +132,6 @@ size_t FileSegment::getDownloadedSize() const
size_t FileSegment::getDownloadedSizeUnlocked(const FileSegmentGuard::Lock &) const size_t FileSegment::getDownloadedSizeUnlocked(const FileSegmentGuard::Lock &) const
{ {
if (download_state == State::DOWNLOADED)
return downloaded_size;
std::unique_lock download_lock(download_mutex);
return downloaded_size; return downloaded_size;
} }
@ -357,8 +353,6 @@ void FileSegment::write(const char * from, size_t size, size_t offset)
{ {
cache_writer->write(from, size); cache_writer->write(from, size);
std::unique_lock download_lock(download_mutex);
cache_writer->next(); cache_writer->next();
downloaded_size += size; downloaded_size += size;

View File

@ -317,7 +317,7 @@ private:
LocalCacheWriterPtr cache_writer; LocalCacheWriterPtr cache_writer;
/// downloaded_size should always be less or equal to reserved_size /// downloaded_size should always be less or equal to reserved_size
size_t downloaded_size = 0; std::atomic<size_t> downloaded_size = 0;
size_t reserved_size = 0; size_t reserved_size = 0;
/// global locking order rule: /// global locking order rule:
@ -328,14 +328,6 @@ private:
LockedKeyCreatorPtr locked_key_creator; LockedKeyCreatorPtr locked_key_creator;
std::condition_variable cv; std::condition_variable cv;
/// Protects downloaded_size access with actual write into fs.
/// downloaded_size is not protected by download_mutex in methods which
/// can never be run in parallel to FileSegment::write() method
/// as downloaded_size is updated only in FileSegment::write() method.
/// Such methods are identified by isDownloader() check at their start,
/// e.g. they are executed strictly by the same thread, sequentially.
mutable std::mutex download_mutex;
Key file_key; Key file_key;
const std::string file_path; const std::string file_path;
FileCache * cache; FileCache * cache;