From 9fbe56a81d75e3b8f0cfdd43b4fc05de48875767 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 21 Oct 2024 16:49:40 +0200 Subject: [PATCH] make file_pool_impl have the open_unmap_lock mutex type configurable by its template parameter --- include/libtorrent/aux_/file_pool.hpp | 7 ++++++- include/libtorrent/aux_/file_pool_impl.hpp | 4 ++-- include/libtorrent/aux_/file_view_pool.hpp | 5 ++++- src/file_pool_impl.cpp | 7 ++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/libtorrent/aux_/file_pool.hpp b/include/libtorrent/aux_/file_pool.hpp index ae48d97e24d..8ac0767c9ee 100644 --- a/include/libtorrent/aux_/file_pool.hpp +++ b/include/libtorrent/aux_/file_pool.hpp @@ -19,12 +19,17 @@ namespace libtorrent::aux { struct file_pool_entry { +#if TORRENT_HAVE_MAP_VIEW_OF_FILE + using mutex_type = int*; + using lock_type = int; +#endif + file_pool_entry(file_id k , string_view name , open_mode_t const m , std::int64_t const size #if TORRENT_HAVE_MAP_VIEW_OF_FILE - , std::shared_ptr + , mutex_type #endif ) : key(k) diff --git a/include/libtorrent/aux_/file_pool_impl.hpp b/include/libtorrent/aux_/file_pool_impl.hpp index 797c21c67ea..4088fe1bfe5 100644 --- a/include/libtorrent/aux_/file_pool_impl.hpp +++ b/include/libtorrent/aux_/file_pool_impl.hpp @@ -73,7 +73,7 @@ namespace libtorrent::aux { FileHandle open_file(storage_index_t st, std::string const& p , file_index_t file_index, file_storage const& fs, open_mode_t m #if TORRENT_HAVE_MAP_VIEW_OF_FILE - , std::shared_ptr open_unmap_lock + , typename FileEntry::mutex_type open_unmap_lock #endif ); @@ -151,7 +151,7 @@ namespace libtorrent::aux { , file_index_t file_index, file_storage const& fs , open_mode_t m, file_id file_key #if TORRENT_HAVE_MAP_VIEW_OF_FILE - , std::shared_ptr open_unmap_lock + , typename FileEntry::mutex_type open_unmap_lock #endif ); diff --git a/include/libtorrent/aux_/file_view_pool.hpp b/include/libtorrent/aux_/file_view_pool.hpp index c0654976e70..2be38239213 100644 --- a/include/libtorrent/aux_/file_view_pool.hpp +++ b/include/libtorrent/aux_/file_view_pool.hpp @@ -23,12 +23,15 @@ namespace libtorrent::aux { struct file_view_entry { + using mutex_type = std::shared_ptr; + using lock_type = std::unique_lock; + file_view_entry(file_id k , string_view name , open_mode_t const m , std::int64_t const size #if TORRENT_HAVE_MAP_VIEW_OF_FILE - , std::shared_ptr open_unmap_lock + , mutex_type open_unmap_lock #endif ) : key(k) diff --git a/src/file_pool_impl.cpp b/src/file_pool_impl.cpp index 494f5a2d711..22c1b54b769 100644 --- a/src/file_pool_impl.cpp +++ b/src/file_pool_impl.cpp @@ -40,7 +40,7 @@ namespace libtorrent::aux { , file_index_t const file_index, file_storage const& fs , open_mode_t const m #if TORRENT_HAVE_MAP_VIEW_OF_FILE - , std::shared_ptr open_unmap_lock + , typename FileEntry::mutex_type open_unmap_lock #endif ) { @@ -232,13 +232,14 @@ namespace libtorrent::aux { , file_index_t const file_index, file_storage const& fs , open_mode_t const m, file_id const file_key #if TORRENT_HAVE_MAP_VIEW_OF_FILE - , std::shared_ptr open_unmap_lock + , typename FileEntry::mutex_type open_unmap_lock #endif ) { std::string const file_path = fs.file_path(file_index, p); #if TORRENT_HAVE_MAP_VIEW_OF_FILE - std::unique_lock lou(*open_unmap_lock); + typename FileEntry::lock_type lou(*open_unmap_lock); + TORRENT_UNUSED(lou); #endif try {