addrman: Add Clang thread safety annotations for variables guarded by CAddrMan.cs #13115

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:guarded-by-cs_addrMan changing 2 files +31 −26
  1. practicalswift commented at 7:06 PM on April 29, 2018: contributor
    • Add Clang thread safety annotations for variables guarded by CAddrMan.cs
    • Add missing CAddrMan.cs locks
  2. laanwj added the label Refactoring on Apr 30, 2018
  3. practicalswift renamed this:
    Add Clang thread safety annotations for variables guarded by cs_addrMan
    addrman: Add Clang thread safety annotations for variables guarded by cs_addrMan
    on Apr 30, 2018
  4. practicalswift cross-referenced this on Apr 30, 2018 from issue Meta-issue: Add Clang thread safety analysis annotations by practicalswift
  5. DrahtBot closed this on Jul 22, 2018

  6. DrahtBot commented at 11:49 PM on July 22, 2018: contributor

    <!--5d09a71f8925f3f132321140b44b946d-->The last travis run for this pull request was 84 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

  7. DrahtBot reopened this on Jul 22, 2018

  8. practicalswift commented at 12:11 PM on August 13, 2018: contributor

    @MarcoFalke Would you mind reviewing this one? Should hopefully be trivial :-)

  9. MarcoFalke commented at 1:21 PM on August 13, 2018: member

    utACK 4f04bda90e113cd596b019c05d6a5cb3ac4be540

  10. practicalswift cross-referenced this on Aug 31, 2018 from issue wallet: Remove unused local variable old_label by practicalswift
  11. DrahtBot cross-referenced this on Sep 12, 2018 from issue p2p: Return a max of 1000 addrs from CAddrMan::GetAddr by Empact
  12. practicalswift commented at 12:36 PM on October 8, 2018: contributor

    @Empact @promag @ajtowns Would you mind reviewing? Should hopefully be trivial :-)

  13. promag commented at 1:45 PM on October 8, 2018: member

    Should squash or invert commit order otherwise 1st commit is broken? Also why rename CAddrMan::cs to CAddrMan::cs_addrMan?

  14. practicalswift force-pushed on Oct 8, 2018
  15. practicalswift commented at 1:51 PM on October 8, 2018: contributor

    @promag Fixed. Please re-review :-)

  16. practicalswift force-pushed on Oct 8, 2018
  17. practicalswift force-pushed on Oct 8, 2018
  18. promag commented at 2:51 PM on October 8, 2018: member

    Unrelated feature_notifications.py failure in appveyor:

    test  2018-10-08T14:19:56.724000Z TestFramework (ERROR): Unexpected exception caught during testing 
      Traceback (most recent call last):
        File "C:\projects\bitcoin\test\functional\test_framework\test_framework.py", line 172, in main
          self.run_test()
        File "C:\projects\bitcoin/test/functional/feature_notifications.py", line 55, in run_test
          os.remove(os.path.join(self.walletnotify_dir, tx_file))
      PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\test_runner_20181008_141018\\feature_notifications_38\\walletnotify\\0b3efb8afc557368538b69c082c9f343b4d9c3f52145405438b98a1384fe13ad'
    
  19. promag commented at 2:53 PM on October 8, 2018: member

    utACK 116e77b.

    nits:

    • commit messages could mention CAddrMan.
    • could squash.
  20. Add missing locks and locking annotations for CAddrMan 3e9f6c821b
  21. practicalswift force-pushed on Oct 8, 2018
  22. practicalswift commented at 3:20 PM on October 8, 2018: contributor

    @promag Thanks for the quick review. Feedback addressed. Please re-review :-)

  23. promag commented at 3:26 PM on October 8, 2018: member

    @practicalswift could drop these EXCLUSIVE_LOCKS_REQUIRED? GUARDED_BY should be enough considering the public interface locks cs, and therefore there aren't atomicity concerns?

    So:

    diff --git a/src/addrman.h b/src/addrman.h
    index a36f7ea10..0d9081252 100644
    --- a/src/addrman.h
    +++ b/src/addrman.h
    @@ -192,31 +192,31 @@ private:
         mutable CCriticalSection cs;
    
         //! last used nId
    -    int nIdCount;
    +    int nIdCount GUARDED_BY(cs);
    
         //! table with information about all nIds
    -    std::map<int, CAddrInfo> mapInfo;
    +    std::map<int, CAddrInfo> mapInfo GUARDED_BY(cs);
    
         //! find an nId based on its network address
    -    std::map<CNetAddr, int> mapAddr;
    +    std::map<CNetAddr, int> mapAddr GUARDED_BY(cs);
    
         //! randomly-ordered vector of all nIds
    -    std::vector<int> vRandom;
    +    std::vector<int> vRandom GUARDED_BY(cs);
    
         // number of "tried" entries
    -    int nTried;
    +    int nTried GUARDED_BY(cs);
    
         //! list of "tried" buckets
    -    int vvTried[ADDRMAN_TRIED_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];
    +    int vvTried[ADDRMAN_TRIED_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] GUARDED_BY(cs);
    
         //! number of (unique) "new" entries
    -    int nNew;
    +    int nNew GUARDED_BY(cs);
    
         //! list of "new" buckets
    -    int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];
    +    int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] GUARDED_BY(cs);
    
         //! last time Good was called (memory only)
    -    int64_t nLastGood;
    +    int64_t nLastGood GUARDED_BY(cs);
    
         //! Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discipline used to resolve these collisions.
         std::set<int> m_tried_collisions;
    
  24. practicalswift commented at 3:39 PM on October 8, 2018: contributor

    @promag I'm not sure I follow here. Is you suggestion to drop all the EXCLUSIVE_LOCKS_REQUIRED:s in this PR? Then it won't compile due to warnings such as:

    addrman.cpp:70:44: error: reading variable 'mapAddr' requires holding mutex 'cs' [-Werror,-Wthread-safety-analysis]
    addrman.cpp:71:15: error: reading variable 'mapAddr' requires holding mutex 'cs' [-Werror,-Wthread-safety-analysis]
    addrman.cpp:75:46: error: reading variable 'mapInfo' requires holding mutex 'cs' [-Werror,-Wthread-safety-analysis]
    […]
    

    What am I missing? :-)

  25. promag commented at 5:06 PM on October 8, 2018: member

    @practicalswift right, sorry about last comment.

    ACK 3e9f6c8.

    Please update PR title and description.

  26. practicalswift renamed this:
    addrman: Add Clang thread safety annotations for variables guarded by cs_addrMan
    addrman: Add Clang thread safety annotations for variables guarded by CAddrMan.cs
    on Oct 8, 2018
  27. practicalswift commented at 9:26 PM on October 8, 2018: contributor

    @MarcoFalke Would you mind re-reviewing your previous utACK? :-)

  28. MarcoFalke commented at 3:54 AM on October 9, 2018: member

    utACK 3e9f6c821b

  29. MarcoFalke merged this on Oct 9, 2018
  30. MarcoFalke closed this on Oct 9, 2018

  31. MarcoFalke referenced this in commit 1d1417430c on Oct 9, 2018
  32. Bushstar cross-referenced this on Oct 11, 2018 from issue Updates from bitcoin/master by Bushstar
  33. LarryRuane referenced this in commit 18af176311 on Apr 5, 2021
  34. LarryRuane cross-referenced this on Apr 5, 2021 from issue Bitcoin 0.18 locking PRs by LarryRuane
  35. random-zebra referenced this in commit 7a538fde99 on Apr 8, 2021
  36. practicalswift deleted the branch on Apr 10, 2021
  37. LarryRuane referenced this in commit e96d8fd46c on Apr 29, 2021
  38. LarryRuane referenced this in commit 7df9aef70c on Jun 1, 2021
  39. PastaPastaPasta referenced this in commit b968ebf34c on Jul 17, 2021
  40. gades referenced this in commit dbbd0a2c9a on May 8, 2022
  41. bitcoin locked this on Aug 18, 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:55 UTC