Skip to content

Commit

Permalink
Use the SEQUENCE_CHECKER macro in WeakPtr instead of manual #ifdefs
Browse files Browse the repository at this point in the history
Bug: NONE
Change-Id: I4267bed9b5e2d47822dfe023c138417d3b60c643
Reviewed-on: https://chromium-review.googlesource.com/577399
Commit-Queue: Hans Wennborg <hans@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487916}
  • Loading branch information
zmodem authored and Commit Bot committed Jul 19, 2017
1 parent c0fffee commit 71f161e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 3 additions & 5 deletions base/memory/weak_ptr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@
namespace base {
namespace internal {

static constexpr uintptr_t kTrueMask = ~static_cast<uintptr_t>(0);
constexpr uintptr_t kTrueMask = ~static_cast<uintptr_t>(0);

WeakReference::Flag::Flag() : is_valid_(kTrueMask) {
#if DCHECK_IS_ON()
// Flags only become bound when checked for validity, or invalidated,
// so that we can check that later validity/invalidation operations on
// the same Flag take place on the same sequenced thread.
sequence_checker_.DetachFromSequence();
#endif
DETACH_FROM_SEQUENCE(sequence_checker_);
}

WeakReference::Flag::Flag(WeakReference::Flag::NullFlagTag) : is_valid_(false) {
// There is no need for sequence_checker_.DetachFromSequence() because the
// There is no need for DETACH_FROM_SEQUENCE(sequence_checker_) because the
// null flag doesn't participate in the sequence checks. See DCHECK in
// Invalidate() and IsValid().

Expand Down
9 changes: 2 additions & 7 deletions base/memory/weak_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ class BASE_EXPORT WeakReference {
DCHECK(!is_valid_);
return 0;
}
DCHECK(sequence_checker_.CalledOnValidSequence())
<< "WeakPtrs must be checked on the same sequenced thread.";
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#endif
return is_valid_;
}
Expand All @@ -129,11 +128,7 @@ class BASE_EXPORT WeakReference {
~Flag();

uintptr_t is_valid_;
#if DCHECK_IS_ON()
// Even if SequenceChecker is an empty class in non-dcheck builds, it still
// takes up space in the class.
SequenceChecker sequence_checker_;
#endif
SEQUENCE_CHECKER(sequence_checker_);
};

WeakReference();
Expand Down

0 comments on commit 71f161e

Please sign in to comment.