Simplify CMutexLock #2004

pull alexanderkjeldaas wants to merge 1 commits into bitcoin:master from alexanderkjeldaas:simplify-cmutexlock changing 1 files +10 −30
  1. alexanderkjeldaas commented at 6:26 AM on November 11, 2012: contributor

    o Remove unused Leave and GetLock functions o Make Enter and TryEnter private. o Simplify Enter and TryEnter. boost::unique_lock doesn't really know whether the mutex it wraps is locked or not when the defer_lock option is used. The boost::recursive_mutex does not expose this information, so unique_lock only infers this knowledge. When taking the lock is defered, it (randomly) assumes that the lock is not taken. boost::unique_lock has the following definition:

        unique_lock(Mutex& m_,defer_lock_t):
            m(&m_),is_locked(false)
        {}
    
        bool owns_lock() const
        {
            return is_locked;
        }
    

    Thus it is a mistake to check owns_lock() in Enter and TryEnter - they will always return false.

  2. sipa commented at 11:48 PM on November 13, 2012: member

    ACK on the code changes, but one nitpick: can you separate the git commit summary (the first line) and the rest? Some git tools assume everything up to the first empty line is the summary.

  3. Simplify CMutexLock
    o Remove unused Leave and GetLock functions
    o Make Enter and TryEnter private.
    o Simplify Enter and TryEnter.
      boost::unique_lock doesn't really know whether the
      mutex it wraps is locked or not when the defer_lock
      option is used.
      The boost::recursive_mutex does not expose this
      information, so unique_lock only infers this
      knowledge.  When taking the lock is defered, it
      (randomly) assumes that the lock is not taken.
      boost::unique_lock has the following definition:
    
            unique_lock(Mutex& m_,defer_lock_t):
                m(&m_),is_locked(false)
            {}
    
            bool owns_lock() const
            {
                return is_locked;
            }
      Thus it is a mistake to check owns_lock() in Enter
      and TryEnter - they will always return false.
    bfc9620799
  4. alexanderkjeldaas commented at 3:12 AM on November 14, 2012: contributor

    Done.

  5. sipa commented at 8:03 PM on November 18, 2012: member

    ACK

  6. Diapolo commented at 10:03 PM on November 18, 2012: none

    Compiles just fine on Windows and causes no obvious problems, can't really comment on the changes though.

  7. BitcoinPullTester commented at 7:26 AM on November 23, 2012: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/bfc96207998c284e2cb6eb99c99b755a161e723d for binaries and test log.

  8. sipa referenced this in commit 3ed1ccb089 on Nov 24, 2012
  9. sipa merged this on Nov 24, 2012
  10. sipa closed this on Nov 24, 2012

  11. laudney referenced this in commit e4b3cce20a on Mar 19, 2014
  12. HashUnlimited referenced this in commit 6bf20625f9 on Apr 6, 2018
  13. KolbyML referenced this in commit fe7c942272 on Dec 5, 2020
  14. 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-17 09:16 UTC

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