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()17void 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 sequence_token_ = base::internal::SequenceToken::GetForCurrentThread(); 24 thread_ref_.store(PlatformThread::CurrentRef(), std::memory_order_release); 25 26 // Rebind the thread and sequence checkers to the current thread/sequence. 27 DETACH_FROM_THREAD(thread_checker); 28 DCHECK_CALLED_ON_VALID_THREAD(thread_checker); 29 30 DETACH_FROM_SEQUENCE(sequence_checker); 31 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker); 32 } 33 34 } // namespace internal 35 } // namespace sequence_manager 36 } // namespace base 37