Do not shadow LOCK's criticalblock variable for LOCK inside LOCK #8472

pull paveljanik wants to merge 1 commits into bitcoin:master from paveljanik:20160806_Wshadow_LOCK changing 1 files +4 −1
  1. paveljanik commented at 9:02 AM on August 6, 2016: contributor

    This is a followup to #8105, implements task 3 from it.

    LOCK macro declares its variable criticalblock. When LOCK is used in nested block, again, the variable named criticalblock is used. When compiling with -Wshadow, this emits warning.

    This change renames the variable criticalblock to criticalblockn, where n is ordinal number of the variable in the compiled file. Macro __COUNTER__ is used for this. It is supported by gcc (https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html), clang (http://clang.llvm.org/docs/LanguageExtensions.html) and Visual Studio (https://msdn.microsoft.com/en-us/library/b0084kay.aspx).

  2. Do not shadow LOCK's criticalblock variable for LOCK inside LOCK 33d15a3a76
  3. jonasschnelli added the label Refactoring on Aug 8, 2016
  4. sipa commented at 5:38 AM on August 10, 2016: member

    utACK 33d15a3a76d073986337adcd62646d93e7ba223f

  5. paveljanik commented at 9:03 AM on August 22, 2016: contributor

    More ACKs please.

  6. dcousens commented at 11:32 AM on August 22, 2016: contributor

    utACK 33d15a3

  7. luke-jr commented at 3:19 AM on August 29, 2016: member

    I'd probably use LINE which is defined in the standards, but in practice it probably doesn't matter.

  8. paveljanik commented at 7:22 AM on August 29, 2016: contributor

    @luke-jr __LINE__ was thought of first, but @theuni raised "valid" (but not used yet) use-case (https://botbot.me/freenode/bitcoin-core-dev/2016-08-05/?msg=70857153&page=4):

    std::mutex m1;
    std::mutex m2;
    LOCK(m1); LOCK(m2);
    

    Of course you can use LOCK2 then instead, but...

    Using __COUNTER__ allows even this use-case.

  9. theuni commented at 4:18 PM on August 29, 2016: member

    @paveljanik just to clarify, I was being snarky there. I don't think that's a real worry. In fact, 2 locks on the same line would almost certainly be wrong, as they should be std::lock()ed for safety anyway. So either way is fine with me.

    utACK 33d15a3a76d073986337adcd62646d93e7ba223f

  10. paveljanik commented at 9:31 AM on August 30, 2016: contributor

    @theuni Ah, OK. Then I think we SHOULD use the standard __LINE__ even if __COUNTER__ works in all environments...

  11. sipa commented at 1:14 PM on August 30, 2016: member

    Using __LINE__ would result in a non-obvious error message, I guess. No strong opinion either way.

  12. paveljanik commented at 4:39 PM on August 30, 2016: contributor

    So let's go with __COUNTER__ and we will see if it is problematic on some systems or if it is de-facto-standard.

  13. laanwj commented at 2:56 PM on August 31, 2016: member

    Microsoft, gcc and clang implement __COUNTER__ so I'd say that's good enough.

    We could even fall back to shadowing if it's not defined?

  14. paveljanik commented at 3:14 PM on August 31, 2016: contributor

    Let's try it and see.

  15. laanwj commented at 12:41 PM on September 1, 2016: member

    ACK, checked that bitcoind stays the same between 6e6ab2c and 33d15a3.

  16. laanwj merged this on Sep 1, 2016
  17. laanwj closed this on Sep 1, 2016

  18. laanwj referenced this in commit 0e563d89c0 on Sep 1, 2016
  19. LarryRuane referenced this in commit aa4835624a on Feb 24, 2021
  20. LarryRuane referenced this in commit 27d328030c on Apr 1, 2021
  21. zkbot referenced this in commit 1b5f17c900 on Apr 1, 2021
  22. zkbot referenced this in commit 80e66e7daa on Apr 2, 2021
  23. DrahtBot locked this on Sep 8, 2021

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-04-22 06:15 UTC

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