Index: base/threading/thread_restrictions.cc |
=================================================================== |
--- base/threading/thread_restrictions.cc (revision 133458) |
+++ base/threading/thread_restrictions.cc (working copy) |
@@ -21,6 +21,9 @@ |
LazyInstance<ThreadLocalBoolean>::Leaky |
g_singleton_disallowed = LAZY_INSTANCE_INITIALIZER; |
+LazyInstance<ThreadLocalBoolean>::Leaky |
+ g_wait_disallowed = LAZY_INSTANCE_INITIALIZER; |
+ |
} // anonymous namespace |
// static |
@@ -42,6 +45,7 @@ |
} |
} |
+// static |
bool ThreadRestrictions::SetSingletonAllowed(bool allowed) { |
bool previous_disallowed = g_singleton_disallowed.Get().Get(); |
g_singleton_disallowed.Get().Set(!allowed); |
@@ -58,6 +62,25 @@ |
} |
} |
+// static |
+void ThreadRestrictions::DisallowWaiting() { |
+ g_wait_disallowed.Get().Set(true); |
+} |
+ |
+// static |
+void ThreadRestrictions::AssertWaitAllowed() { |
+ if (g_wait_disallowed.Get().Get()) { |
+ LOG(FATAL) << "Waiting is not allowed to be used on this thread to prevent" |
+ << "jank and deadlock."; |
+ } |
+} |
+ |
+bool ThreadRestrictions::SetWaitAllowed(bool allowed) { |
+ bool previous_disallowed = g_wait_disallowed.Get().Get(); |
+ g_wait_disallowed.Get().Set(!allowed); |
+ return !previous_disallowed; |
+} |
+ |
} // namespace base |
#endif // NDEBUG |