util: Get rid of RecursiveMutex in Get{Blocks,Data}Dir #19213

pull hebasto wants to merge 2 commits into bitcoin:master from hebasto:200608-path-mx changing 1 files +13 −11
  1. hebasto commented at 5:54 PM on June 8, 2020: member

    Another step on the way to replacing all of the RecursiveMutex instances with the Mutex ones.

    This PR removes the RecursiveMutex object by splitting it into two Mutex objects, and ensuring they are always acquired in the same order.

    Related to #19303.

  2. DrahtBot added the label Refactoring on Jun 8, 2020
  3. DrahtBot added the label Utils/log/libs on Jun 8, 2020
  4. in src/util/system.cpp:676 in f7f41a0810 outdated
     596 | +static fs::path g_blocks_path_cache_net_specific GUARDED_BY(g_path_cache_mutex);
     597 | +static fs::path pathCached GUARDED_BY(g_path_cache_mutex);
     598 | +static fs::path pathCachedNetSpecific GUARDED_BY(g_path_cache_mutex);
     599 |  
     600 | -const fs::path &GetBlocksDir()
     601 | +namespace {
    


    vasild commented at 7:19 PM on June 8, 2020:

    Why is this namespace required?


  5. vasild approved
  6. vasild commented at 7:21 PM on June 8, 2020: contributor

    ACK f7f41a08

  7. DrahtBot cross-referenced this on Jun 16, 2020 from issue Replace boost::filesystem with std::filesystem by kiminuo
  8. DrahtBot commented at 11:16 PM on June 16, 2020: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #21244 (Move GetDataDir to ArgsManager by kiminuo)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  9. hebasto cross-referenced this on Jun 17, 2020 from issue Replace all of the RecursiveMutex instances with the Mutex ones by hebasto
  10. DrahtBot cross-referenced this on Jul 8, 2020 from issue Use operator/ in fs::absolute to prepare for C++17 by kiminuo
  11. hebasto marked this as a draft on Oct 6, 2020
  12. DrahtBot cross-referenced this on Oct 16, 2020 from issue Strip any trailing `/` in -datadir and -blocksdir paths by hebasto
  13. hebasto marked this as ready for review on Nov 8, 2020
  14. hebasto force-pushed on Nov 8, 2020
  15. hebasto renamed this:
    refactor: Replace RecursiveMutex with Mutex in Get{Data,Blocks}Dir()
    util: Get rid of RecursiveMutex in Get{Blocks,Data}Dir
    on Nov 8, 2020
  16. hebasto commented at 8:56 PM on November 8, 2020: member

    Reworked without introducing a new helper function.

    ping @vasild @promag @MarcoFalke

  17. in src/util/system.cpp:695 in 0173e68845 outdated
     695 |  
     696 |  const fs::path &GetBlocksDir()
     697 |  {
     698 | -    LOCK(csPathCached);
     699 | +    LOCK(g_blocksdir_path_mutex);
     700 |      fs::path &path = g_blocks_path_cache_net_specific;
    


    vasild commented at 10:03 AM on November 9, 2020:

    Assuming g_blocksdir_path_mutex protects just the variable g_blocks_path_cache_net_specific, would it be possible to release the mutex after this assignment?

    If "yes", then I would suggest to do it as a good practice of minimizing the time a mutex is held and also to avoid holding it together with the other newly introduced g_datadir_path_mutex.

    If "no" then I think it is warranted to explain in a comment next to g_blocksdir_path_mutex what exactly is protected by it.


    hebasto commented at 10:57 AM on November 9, 2020:

    Assuming g_blocksdir_path_mutex protects just the variable g_blocks_path_cache_net_specific, would it be possible to release the mutex after this assignment?

    I guess not, as the path references to the same memory location as the g_blocks_path_cache_net_specific variable, that must be protected by the g_blocksdir_path_mutex.


    hebasto commented at 10:58 AM on November 9, 2020:

    If "no" then I think it is warranted to explain in a comment next to g_blocksdir_path_mutex what exactly is protected by it.

    I think GUARDED_BY is pretty self-documented annotation, no?


    vasild commented at 2:15 PM on November 9, 2020:

    oh well, I overlooked the fact that it is being assigned to a reference

  18. vasild commented at 10:06 AM on November 9, 2020: contributor

    Looks good.

    The commit message reads just

    util: Get rid of RecursiveMutex in Get{Blocks,Data}Dir

    maybe it would be good to explain that we remove the recursive mutex by splitting it to two mutexes and ensuring they are always acquired in the same order.

  19. util: Get rid of RecursiveMutex in Get{Blocks,Data}Dir
    This change removes the RecursiveMutex object by splitting it into two
    Mutex objects, and ensuring they are always acquired in the same order.
    62d41358c1
  20. scripted-diff: Rename datadir path variables in util/system.cpp
    -BEGIN VERIFY SCRIPT-
    sed -i 's/pathCachedNetSpecific/g_datadir_path_cached_net_specific/' src/util/system.cpp
    sed -i 's/pathCached/g_datadir_path_cached/' src/util/system.cpp
    -END VERIFY SCRIPT-
    7b90f77146
  21. hebasto force-pushed on Nov 9, 2020
  22. hebasto commented at 11:19 AM on November 9, 2020: member

    Updated 0173e6884568bf9f03d08b80ffc0b80729378e44 -> 7b90f77146d36ef21760f2ce3704e2f2f463b3a2 (pr19213.02 -> pr19213.03, diff):

    Looks good.

    The commit message reads just

    util: Get rid of RecursiveMutex in Get{Blocks,Data}Dir

    maybe it would be good to explain that we remove the recursive mutex by splitting it to two mutexes and ensuring they are always acquired in the same order.

  23. vasild approved
  24. vasild commented at 2:14 PM on November 9, 2020: contributor

    ACK 7b90f7714

  25. DrahtBot cross-referenced this on Feb 20, 2021 from issue Move GetDataDir to ArgsManager by kiminuo
  26. DrahtBot added the label Needs rebase on Apr 20, 2021
  27. DrahtBot commented at 2:33 AM on April 20, 2021: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

    <sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>

  28. hebasto closed this on Apr 20, 2021

  29. vasild commented at 1:35 PM on April 20, 2021: contributor

    Why close?

  30. hebasto commented at 2:06 PM on April 20, 2021: member

    Why close?

    It is incompatible with #21244.

  31. bitcoin locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:54 UTC