Commit 483aa2cc authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Hide implementations of ScopedAllowIO/ScopedAllowWait like other scoped thread restrictions objects

Re-uses existing helpers to make these truly empty impls in non-dcheck
builds.

Most importantly, this allows instrumenting these calls with extra
tracing information when debugging without having to rebuild the world
(thread_restrictions.h is implicitly included virtually everywhere).

(and yes they should be outright removed in favor of the new ones but
that's orthogonal to this CL)

R=fdoray@chromium.org

Bug: gab doesn't like to rebuild the world when debugging
Change-Id: I6f7f39a26164c4375fd9b48233236a528b0fa2b5
Reviewed-on: https://chromium-review.googlesource.com/969446
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544340}
parent 6cf2793f
......@@ -118,6 +118,13 @@ void ResetThreadRestrictionsForTesting() {
} // namespace internal
ThreadRestrictions::ScopedAllowIO::ScopedAllowIO()
: was_allowed_(SetIOAllowed(true)) {}
ThreadRestrictions::ScopedAllowIO::~ScopedAllowIO() {
SetIOAllowed(was_allowed_);
}
// static
bool ThreadRestrictions::SetIOAllowed(bool allowed) {
bool previous_disallowed = g_blocking_disallowed.Get().Get();
......@@ -157,6 +164,13 @@ bool ThreadRestrictions::SetWaitAllowed(bool allowed) {
return !previous_disallowed;
}
ThreadRestrictions::ScopedAllowWait::ScopedAllowWait()
: was_allowed_(SetWaitAllowed(true)) {}
ThreadRestrictions::ScopedAllowWait::~ScopedAllowWait() {
SetWaitAllowed(was_allowed_);
}
} // namespace base
#endif // DCHECK_IS_ON()
......@@ -359,11 +359,13 @@ class BASE_EXPORT ThreadRestrictions {
// DEPRECATED. Use ScopedAllowBlocking(ForTesting).
class BASE_EXPORT ScopedAllowIO {
public:
ScopedAllowIO() { previous_value_ = SetIOAllowed(true); }
~ScopedAllowIO() { SetIOAllowed(previous_value_); }
ScopedAllowIO() EMPTY_BODY_IF_DCHECK_IS_OFF;
~ScopedAllowIO() EMPTY_BODY_IF_DCHECK_IS_OFF;
private:
// Whether IO is allowed when the ScopedAllowIO was constructed.
bool previous_value_;
#if DCHECK_IS_ON()
const bool was_allowed_;
#endif
DISALLOW_COPY_AND_ASSIGN(ScopedAllowIO);
};
......@@ -470,12 +472,13 @@ class BASE_EXPORT ThreadRestrictions {
// DEPRECATED. Use ScopedAllowBaseSyncPrimitives.
class BASE_EXPORT ScopedAllowWait {
public:
ScopedAllowWait() { previous_value_ = SetWaitAllowed(true); }
~ScopedAllowWait() { SetWaitAllowed(previous_value_); }
ScopedAllowWait() EMPTY_BODY_IF_DCHECK_IS_OFF;
~ScopedAllowWait() EMPTY_BODY_IF_DCHECK_IS_OFF;
private:
// Whether singleton use is allowed when the ScopedAllowWait was
// constructed.
bool previous_value_;
#if DCHECK_IS_ON()
const bool was_allowed_;
#endif
DISALLOW_COPY_AND_ASSIGN(ScopedAllowWait);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment