OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 else | 411 else |
412 pump_ = CreateMessagePumpForType(type_); | 412 pump_ = CreateMessagePumpForType(type_); |
413 | 413 |
414 DCHECK(!current()) << "should only have one message loop per thread"; | 414 DCHECK(!current()) << "should only have one message loop per thread"; |
415 lazy_tls_ptr.Pointer()->Set(this); | 415 lazy_tls_ptr.Pointer()->Set(this); |
416 | 416 |
417 incoming_task_queue_->StartScheduling(); | 417 incoming_task_queue_->StartScheduling(); |
418 unbound_task_runner_->BindToCurrentThread(); | 418 unbound_task_runner_->BindToCurrentThread(); |
419 unbound_task_runner_ = nullptr; | 419 unbound_task_runner_ = nullptr; |
420 SetThreadTaskRunnerHandle(); | 420 SetThreadTaskRunnerHandle(); |
421 { | 421 thread_id_ = PlatformThread::CurrentId(); |
422 // Save the current thread's ID for potential use by other threads | |
423 // later from GetThreadName(). | |
424 thread_id_ = PlatformThread::CurrentId(); | |
425 subtle::MemoryBarrier(); | |
426 } | |
427 } | 422 } |
428 | 423 |
429 std::string MessageLoop::GetThreadName() const { | 424 std::string MessageLoop::GetThreadName() const { |
430 if (thread_id_ == kInvalidThreadId) { | 425 DCHECK_NE(kInvalidThreadId, thread_id_) |
431 // |thread_id_| may already have been initialized but this thread might not | 426 << "GetThreadName() must only be called after BindToCurrentThread()'s " |
432 // have received the update yet. | 427 << "side-effects have been synchronized with this thread."; |
433 subtle::MemoryBarrier(); | |
434 DCHECK_NE(kInvalidThreadId, thread_id_); | |
435 } | |
436 return ThreadIdNameManager::GetInstance()->GetName(thread_id_); | 428 return ThreadIdNameManager::GetInstance()->GetName(thread_id_); |
437 } | 429 } |
438 | 430 |
439 void MessageLoop::SetTaskRunner( | 431 void MessageLoop::SetTaskRunner( |
440 scoped_refptr<SingleThreadTaskRunner> task_runner) { | 432 scoped_refptr<SingleThreadTaskRunner> task_runner) { |
441 DCHECK_EQ(this, current()); | 433 DCHECK_EQ(this, current()); |
442 DCHECK(task_runner->BelongsToCurrentThread()); | 434 DCHECK(task_runner->BelongsToCurrentThread()); |
443 DCHECK(!unbound_task_runner_); | 435 DCHECK(!unbound_task_runner_); |
444 task_runner_ = std::move(task_runner); | 436 task_runner_ = std::move(task_runner); |
445 SetThreadTaskRunnerHandle(); | 437 SetThreadTaskRunnerHandle(); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 persistent, | 763 persistent, |
772 mode, | 764 mode, |
773 controller, | 765 controller, |
774 delegate); | 766 delegate); |
775 } | 767 } |
776 #endif | 768 #endif |
777 | 769 |
778 #endif // !defined(OS_NACL_SFI) | 770 #endif // !defined(OS_NACL_SFI) |
779 | 771 |
780 } // namespace base | 772 } // namespace base |
OLD | NEW |