• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Chromium Authors
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/task/sequence_manager/associated_thread_id.h"
6 
7 #include "base/check.h"
8 #include "base/dcheck_is_on.h"
9 
10 namespace base {
11 namespace sequence_manager {
12 namespace internal {
13 
14 AssociatedThreadId::AssociatedThreadId() = default;
15 AssociatedThreadId::~AssociatedThreadId() = default;
16 
BindToCurrentThread()17 void AssociatedThreadId::BindToCurrentThread() {
18 #if DCHECK_IS_ON()
19   const auto prev_thread_ref = thread_ref_.load(std::memory_order_relaxed);
20   DCHECK(prev_thread_ref.is_null() ||
21          prev_thread_ref == PlatformThread::CurrentRef());
22 #endif
23   thread_ref_.store(PlatformThread::CurrentRef(), std::memory_order_release);
24 
25   // Rebind the thread and sequence checkers to the current thread/sequence.
26   DETACH_FROM_THREAD(thread_checker);
27   DCHECK_CALLED_ON_VALID_THREAD(thread_checker);
28 
29   DETACH_FROM_SEQUENCE(sequence_checker);
30   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker);
31 }
32 
33 }  // namespace internal
34 }  // namespace sequence_manager
35 }  // namespace base
36