Skip to content

Commit

Permalink
make file_pool_impl have the open_unmap_lock mutex type configurable …
Browse files Browse the repository at this point in the history
…by its template parameter
  • Loading branch information
arvidn committed Oct 21, 2024
1 parent cc70196 commit 9fbe56a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
7 changes: 6 additions & 1 deletion include/libtorrent/aux_/file_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex>
, mutex_type
#endif
)
: key(k)
Expand Down
4 changes: 2 additions & 2 deletions include/libtorrent/aux_/file_pool_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> open_unmap_lock
, typename FileEntry::mutex_type open_unmap_lock
#endif
);

Expand Down Expand Up @@ -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<std::mutex> open_unmap_lock
, typename FileEntry::mutex_type open_unmap_lock
#endif
);

Expand Down
5 changes: 4 additions & 1 deletion include/libtorrent/aux_/file_view_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ namespace libtorrent::aux {

struct file_view_entry
{
using mutex_type = std::shared_ptr<std::mutex>;
using lock_type = std::unique_lock<std::mutex>;

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<std::mutex> open_unmap_lock
, mutex_type open_unmap_lock
#endif
)
: key(k)
Expand Down
7 changes: 4 additions & 3 deletions src/file_pool_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> open_unmap_lock
, typename FileEntry::mutex_type open_unmap_lock
#endif
)
{
Expand Down Expand Up @@ -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<std::mutex> 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<std::mutex> lou(*open_unmap_lock);
typename FileEntry::lock_type lou(*open_unmap_lock);
TORRENT_UNUSED(lou);
#endif
try
{
Expand Down

0 comments on commit 9fbe56a

Please sign in to comment.