OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/thread_restrictions.h" |
| 6 |
| 7 // This entire file is compiled out in Release mode. |
| 8 #ifndef NDEBUG |
| 9 |
| 10 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/thread_local.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 static base::LazyInstance<base::ThreadLocalBoolean> |
| 17 g_io_disallowed(base::LINKER_INITIALIZED); |
| 18 |
| 19 } // anonymous namespace |
| 20 |
| 21 namespace base { |
| 22 |
| 23 // static |
| 24 void ThreadRestrictions::SetIOAllowed(bool allowed) { |
| 25 g_io_disallowed.Get().Set(!allowed); |
| 26 } |
| 27 |
| 28 // static |
| 29 void ThreadRestrictions::AssertIOAllowed() { |
| 30 if (g_io_disallowed.Get().Get()) { |
| 31 LOG(FATAL) << |
| 32 "Function marked as IO-only was called from a thread that " |
| 33 "disallows IO! If this thread really should be allowed to " |
| 34 "make IO calls, adjust the call to " |
| 35 "base::ThreadRestrictions::SetIOAllowed() in this thread's " |
| 36 "startup."; |
| 37 } |
| 38 } |
| 39 |
| 40 } // namespace base |
| 41 |
| 42 #endif // NDEBUG |
OLD | NEW |