Introduce SequenceChecker/ThreadChecker macros, so they have zero impact on non-DCHECK builds |
|||
Issue description
The *Checker helpers have DoNothing implementations for non-DCHECK builds, which are intended to have them incur zero overhead in production binaries. C++ isn't actually allowed to allocate zero bytes for members of empty-class types, though, so this doesn't quite have the desired effect.
fdoray@ proposed that we replace the classes & checks with macros, so they can be compiled out entirely, without depending on any compiler cleverness:
--
1) Introduce THREAD/SEQUENCE_CHECKER and ASSERT_CALLED_ON_VALID_THREAD/SEQUENCE macros that can be used like this:
class A {
public:
void MyMethod() {
ASSERT_CALLED_ON_VALID_THREAD(thread_checker_);
}
private:
THREAD_CHECKER(thread_checker_);
};
These macros are expanded to nothing when !DCHECK_IS_ON().
2) Move existing uses of ThreadChecker and SequenceChecker to these macros.
3) For every ~230 instance of base::NonThreadSafe (https://cs.chromium.org/search/?q=base::NonThreadSafe&p=2&type=cs), upload a CL that replaces the base::NonThreadSafe inheritance with a SEQUENCE_CHECKER member. In the CL message, ask the reviewer to validate that the use of SEQUENCE_CHECKER instead of THREAD_CHECKER is appropriate (with documentation of differences between the two options). Use an automated script to switch to THREAD_CHECKER when the reviewer asks for it.
4) Remove base::NonThreadSafe.
--
,
Apr 26 2017
Thanks for filling this, there is also issue 676387 tracking making NonThreadSafe sequence-friendly which will now happen more or less in sync. Those are the use cases I'll tackle first but refactoring the remaining use cases after that should be fairly easy.
,
May 5 2017
,
May 11 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/d52c912abb8accf430d7ba7e7d368b2638a4c8fa commit d52c912abb8accf430d7ba7e7d368b2638a4c8fa Author: gab <gab@chromium.org> Date: Thu May 11 04:15:59 2017 New Sequence/Thread checking API. Macro-based to be zero size cost in non-dcheck builds. Based on discussion @ https://groups.google.com/a/chromium.org/d/topic/chromium-dev/99pKNd2kCcg/discussion BUG= 714835 Review-Url: https://codereview.chromium.org/2869893003 Cr-Commit-Position: refs/heads/master@{#470804} [modify] https://crrev.com/d52c912abb8accf430d7ba7e7d368b2638a4c8fa/PRESUBMIT.py [modify] https://crrev.com/d52c912abb8accf430d7ba7e7d368b2638a4c8fa/base/sequence_checker.h [modify] https://crrev.com/d52c912abb8accf430d7ba7e7d368b2638a4c8fa/base/sequence_checker_unittest.cc [modify] https://crrev.com/d52c912abb8accf430d7ba7e7d368b2638a4c8fa/base/threading/non_thread_safe.h [modify] https://crrev.com/d52c912abb8accf430d7ba7e7d368b2638a4c8fa/base/threading/thread_checker.h [modify] https://crrev.com/d52c912abb8accf430d7ba7e7d368b2638a4c8fa/base/threading/thread_checker_unittest.cc
,
May 24 2017
Macros introduced, replacing NonThreadSafe tracked in issue 676387 . |
|||
►
Sign in to add a comment |
|||
Comment 1 by w...@chromium.org
, Apr 26 2017Status: Assigned (was: Untriaged)