// Copyright 2021 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/common/protobuf_init.h" #include #include "base/check.h" #include "base/no_destructor.h" #include "base/threading/scoped_thread_priority.h" #include "base/threading/thread_local.h" namespace chrome { namespace { using ScopedBoostThreadPriority = base::internal::ScopedMayLoadLibraryAtBackgroundPriority; using ScopedBoostThreadPriorityTLS = base::ThreadLocalPointer; ScopedBoostThreadPriorityTLS& GetScopedBoostThreadPriorityTLS() { static base::NoDestructor tls_slot; return *tls_slot; } void EnterInitSCC() { DCHECK(!GetScopedBoostThreadPriorityTLS().Get()); GetScopedBoostThreadPriorityTLS().Set( new ScopedBoostThreadPriority(FROM_HERE, nullptr)); } void LeaveInitSCC() { DCHECK(GetScopedBoostThreadPriorityTLS().Get()); ScopedBoostThreadPriority* boost_thread_priority = GetScopedBoostThreadPriorityTLS().Get(); delete boost_thread_priority; GetScopedBoostThreadPriorityTLS().Set(nullptr); } } // namespace void InitializeProtobuf() { google::protobuf::internal::RegisterInitSCCHooks(EnterInitSCC, LeaveInitSCC); } } // namespace chrome