| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 } | 301 } |
| 302 | 302 |
| 303 // static | 303 // static |
| 304 bool BrowserThreadImpl::PostTaskHelper( | 304 bool BrowserThreadImpl::PostTaskHelper( |
| 305 BrowserThread::ID identifier, | 305 BrowserThread::ID identifier, |
| 306 const tracked_objects::Location& from_here, | 306 const tracked_objects::Location& from_here, |
| 307 const base::Closure& task, | 307 const base::Closure& task, |
| 308 base::TimeDelta delay, | 308 base::TimeDelta delay, |
| 309 bool nestable) { | 309 bool nestable) { |
| 310 DCHECK(identifier >= 0 && identifier < ID_COUNT); | 310 DCHECK(identifier >= 0 && identifier < ID_COUNT); |
| 311 // We don't want to create a pool if none exists. |
| 312 if (g_globals == NULL) |
| 313 return false; |
| 311 // Optimization: to avoid unnecessary locks, we listed the ID enumeration in | 314 // Optimization: to avoid unnecessary locks, we listed the ID enumeration in |
| 312 // order of lifetime. So no need to lock if we know that the target thread | 315 // order of lifetime. So no need to lock if we know that the target thread |
| 313 // outlives current thread. | 316 // outlives current thread. |
| 314 // Note: since the array is so small, ok to loop instead of creating a map, | 317 // Note: since the array is so small, ok to loop instead of creating a map, |
| 315 // which would require a lock because std::map isn't thread safe, defeating | 318 // which would require a lock because std::map isn't thread safe, defeating |
| 316 // the whole purpose of this optimization. | 319 // the whole purpose of this optimization. |
| 317 BrowserThread::ID current_thread = ID_COUNT; | 320 BrowserThread::ID current_thread = ID_COUNT; |
| 318 bool target_thread_outlives_current = | 321 bool target_thread_outlives_current = |
| 319 GetCurrentThreadIdentifier(¤t_thread) && | 322 GetCurrentThreadIdentifier(¤t_thread) && |
| 320 current_thread >= identifier; | 323 current_thread >= identifier; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 543 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
| 541 &globals.thread_delegates[identifier]); | 544 &globals.thread_delegates[identifier]); |
| 542 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 545 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
| 543 storage, reinterpret_cast<AtomicWord>(delegate)); | 546 storage, reinterpret_cast<AtomicWord>(delegate)); |
| 544 | 547 |
| 545 // This catches registration when previously registered. | 548 // This catches registration when previously registered. |
| 546 DCHECK(!delegate || !old_pointer); | 549 DCHECK(!delegate || !old_pointer); |
| 547 } | 550 } |
| 548 | 551 |
| 549 } // namespace content | 552 } // namespace content |
| OLD | NEW |