New issue
Advanced search Search tips

Issue 714835 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: May 2017
Cc:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug

Blocking:
issue 676387



Sign in to add a comment

Introduce SequenceChecker/ThreadChecker macros, so they have zero impact on non-DCHECK builds

Project Member Reported by w...@chromium.org, Apr 24 2017

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.
--

 

Comment 1 by w...@chromium.org, Apr 26 2017

Owner: gab@chromium.org
Status: Assigned (was: Untriaged)

Comment 2 by gab@chromium.org, 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.

Comment 3 by gab@chromium.org, May 5 2017

Blocking: 676387

Comment 5 by gab@chromium.org, May 24 2017

Status: Fixed (was: Assigned)
Summary: Introduce SequenceChecker/ThreadChecker macros, so they have zero impact on non-DCHECK builds (was: Replace SequenceChecker/ThreadChecker with macros, so they have zero impact on non-DCHECK builds)
Macros introduced, replacing NonThreadSafe tracked in  issue 676387 .

Sign in to add a comment