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: member
    ACK f7f41a08
  7. DrahtBot commented at 11:16 pm on June 16, 2020: member

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

    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.

  8. hebasto marked this as a draft on Oct 6, 2020
  9. hebasto marked this as ready for review on Nov 8, 2020
  10. hebasto force-pushed on Nov 8, 2020
  11. 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
  12. hebasto commented at 8:56 pm on November 8, 2020: member

    Reworked without introducing a new helper function.

    ping @vasild @promag @MarcoFalke

  13. 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
  14. vasild commented at 10:06 am on November 9, 2020: member

    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.

  15. 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
  16. 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
  17. hebasto force-pushed on Nov 9, 2020
  18. 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.

  19. vasild approved
  20. vasild commented at 2:14 pm on November 9, 2020: member
    ACK 7b90f7714
  21. DrahtBot added the label Needs rebase on Apr 20, 2021
  22. DrahtBot commented at 2:33 am on April 20, 2021: member

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

    Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a “draft”.

  23. hebasto closed this on Apr 20, 2021

  24. vasild commented at 1:35 pm on April 20, 2021: member
    Why close?
  25. hebasto commented at 2:06 pm on April 20, 2021: member

    Why close?

    It is incompatible with #21244.

  26. DrahtBot 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: 2024-07-05 19:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me