Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / tools / profiler / core / ProfilerThreadRegistry.cpp
bloba7eb700ef3ea2a944b91ebcb8d5d3f4e1a5c90ae
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/ProfilerThreadRegistry.h"
9 namespace mozilla::profiler {
11 /* static */
12 MOZ_RUNINIT ThreadRegistry::RegistryContainer
13 ThreadRegistry::sRegistryContainer;
15 /* static */
16 MOZ_RUNINIT ThreadRegistry::RegistryMutex ThreadRegistry::sRegistryMutex;
18 #if !defined(MOZ_GECKO_PROFILER)
19 // When MOZ_GECKO_PROFILER is not defined, the function definitions in
20 // platform.cpp are not built, causing link errors. So we keep these simple
21 // definitions here.
23 /* static */
24 void ThreadRegistry::Register(ThreadRegistration::OnThreadRef aOnThreadRef) {
25 LockedRegistry lock;
26 MOZ_RELEASE_ASSERT(sRegistryContainer.append(OffThreadRef{aOnThreadRef}));
29 /* static */
30 void ThreadRegistry::Unregister(ThreadRegistration::OnThreadRef aOnThreadRef) {
31 LockedRegistry lock;
32 for (OffThreadRef& thread : sRegistryContainer) {
33 if (thread.IsPointingAt(*aOnThreadRef.mThreadRegistration)) {
34 sRegistryContainer.erase(&thread);
35 break;
39 #endif // !defined(MOZ_GECKO_PROFILER)
41 } // namespace mozilla::profiler