OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/browser_thread_impl.h" | 5 #include "content/browser/browser_thread_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 void BrowserThreadImpl::ShutdownThreadPool() { | 80 void BrowserThreadImpl::ShutdownThreadPool() { |
81 // The goal is to make it impossible for chrome to 'infinite loop' during | 81 // The goal is to make it impossible for chrome to 'infinite loop' during |
82 // shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks queued | 82 // shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks queued |
83 // during shutdown get run. There's nothing particularly scientific about the | 83 // during shutdown get run. There's nothing particularly scientific about the |
84 // number chosen. | 84 // number chosen. |
85 const int kMaxNewShutdownBlockingTasks = 1000; | 85 const int kMaxNewShutdownBlockingTasks = 1000; |
86 BrowserThreadGlobals& globals = g_globals.Get(); | 86 BrowserThreadGlobals& globals = g_globals.Get(); |
87 globals.blocking_pool->Shutdown(kMaxNewShutdownBlockingTasks); | 87 globals.blocking_pool->Shutdown(kMaxNewShutdownBlockingTasks); |
88 } | 88 } |
89 | 89 |
| 90 // static |
| 91 void BrowserThreadImpl::FlushThreadPoolHelper() { |
| 92 // We don't want to create a pool if none exists. |
| 93 if (g_globals == NULL) |
| 94 return; |
| 95 g_globals.Get().blocking_pool->FlushForTesting(); |
| 96 } |
| 97 |
90 void BrowserThreadImpl::Init() { | 98 void BrowserThreadImpl::Init() { |
91 BrowserThreadGlobals& globals = g_globals.Get(); | 99 BrowserThreadGlobals& globals = g_globals.Get(); |
92 | 100 |
93 using base::subtle::AtomicWord; | 101 using base::subtle::AtomicWord; |
94 AtomicWord* storage = | 102 AtomicWord* storage = |
95 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); | 103 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier_]); |
96 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); | 104 AtomicWord stored_pointer = base::subtle::NoBarrier_Load(storage); |
97 BrowserThreadDelegate* delegate = | 105 BrowserThreadDelegate* delegate = |
98 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); | 106 reinterpret_cast<BrowserThreadDelegate*>(stored_pointer); |
99 if (delegate) | 107 if (delegate) |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 476 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
469 &globals.thread_delegates[identifier]); | 477 &globals.thread_delegates[identifier]); |
470 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 478 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
471 storage, reinterpret_cast<AtomicWord>(delegate)); | 479 storage, reinterpret_cast<AtomicWord>(delegate)); |
472 | 480 |
473 // This catches registration when previously registered. | 481 // This catches registration when previously registered. |
474 DCHECK(!delegate || !old_pointer); | 482 DCHECK(!delegate || !old_pointer); |
475 } | 483 } |
476 | 484 |
477 } // namespace content | 485 } // namespace content |
OLD | NEW |