| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/web/web_thread_impl.h" | 5 #include "ios/web/web_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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 return false; | 361 return false; |
| 362 | 362 |
| 363 WebThreadGlobals& globals = g_globals.Get(); | 363 WebThreadGlobals& globals = g_globals.Get(); |
| 364 base::AutoLock lock(globals.lock); | 364 base::AutoLock lock(globals.lock); |
| 365 DCHECK(identifier >= 0 && identifier < ID_COUNT); | 365 DCHECK(identifier >= 0 && identifier < ID_COUNT); |
| 366 return globals.threads[identifier] != nullptr; | 366 return globals.threads[identifier] != nullptr; |
| 367 } | 367 } |
| 368 | 368 |
| 369 // static | 369 // static |
| 370 bool WebThread::CurrentlyOn(ID identifier) { | 370 bool WebThread::CurrentlyOn(ID identifier) { |
| 371 // This shouldn't use MessageLoop::current() since it uses LazyInstance which | |
| 372 // may be deleted by ~AtExitManager when a WorkerPool thread calls this | |
| 373 // function. | |
| 374 // http://crbug.com/63678 | |
| 375 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; | |
| 376 WebThreadGlobals& globals = g_globals.Get(); | 371 WebThreadGlobals& globals = g_globals.Get(); |
| 377 base::AutoLock lock(globals.lock); | 372 base::AutoLock lock(globals.lock); |
| 378 DCHECK(identifier >= 0 && identifier < ID_COUNT); | 373 DCHECK(identifier >= 0 && identifier < ID_COUNT); |
| 379 return globals.threads[identifier] && | 374 return globals.threads[identifier] && |
| 380 globals.threads[identifier]->message_loop() == | 375 globals.threads[identifier]->message_loop() == |
| 381 base::MessageLoop::current(); | 376 base::MessageLoop::current(); |
| 382 } | 377 } |
| 383 | 378 |
| 384 // static | 379 // static |
| 385 std::string WebThread::GetDCheckCurrentlyOnErrorMessage(ID expected) { | 380 std::string WebThread::GetDCheckCurrentlyOnErrorMessage(ID expected) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 const base::Closure& reply) { | 444 const base::Closure& reply) { |
| 450 return GetTaskRunnerForThread(identifier) | 445 return GetTaskRunnerForThread(identifier) |
| 451 ->PostTaskAndReply(from_here, task, reply); | 446 ->PostTaskAndReply(from_here, task, reply); |
| 452 } | 447 } |
| 453 | 448 |
| 454 // static | 449 // static |
| 455 bool WebThread::GetCurrentThreadIdentifier(ID* identifier) { | 450 bool WebThread::GetCurrentThreadIdentifier(ID* identifier) { |
| 456 if (g_globals == nullptr) | 451 if (g_globals == nullptr) |
| 457 return false; | 452 return false; |
| 458 | 453 |
| 459 // This shouldn't use MessageLoop::current() since it uses LazyInstance which | |
| 460 // may be deleted by ~AtExitManager when a WorkerPool thread calls this | |
| 461 // function. | |
| 462 // http://crbug.com/63678 | |
| 463 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; | |
| 464 base::MessageLoop* cur_message_loop = base::MessageLoop::current(); | 454 base::MessageLoop* cur_message_loop = base::MessageLoop::current(); |
| 465 WebThreadGlobals& globals = g_globals.Get(); | 455 WebThreadGlobals& globals = g_globals.Get(); |
| 466 for (int i = 0; i < ID_COUNT; ++i) { | 456 for (int i = 0; i < ID_COUNT; ++i) { |
| 467 if (globals.threads[i] && | 457 if (globals.threads[i] && |
| 468 globals.threads[i]->message_loop() == cur_message_loop) { | 458 globals.threads[i]->message_loop() == cur_message_loop) { |
| 469 *identifier = globals.threads[i]->identifier_; | 459 *identifier = globals.threads[i]->identifier_; |
| 470 return true; | 460 return true; |
| 471 } | 461 } |
| 472 } | 462 } |
| 473 | 463 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 487 AtomicWord* storage = | 477 AtomicWord* storage = |
| 488 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier]); | 478 reinterpret_cast<AtomicWord*>(&globals.thread_delegates[identifier]); |
| 489 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 479 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
| 490 storage, reinterpret_cast<AtomicWord>(delegate)); | 480 storage, reinterpret_cast<AtomicWord>(delegate)); |
| 491 | 481 |
| 492 // This catches registration when previously registered. | 482 // This catches registration when previously registered. |
| 493 DCHECK(!delegate || !old_pointer); | 483 DCHECK(!delegate || !old_pointer); |
| 494 } | 484 } |
| 495 | 485 |
| 496 } // namespace web | 486 } // namespace web |
| OLD | NEW |