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/. */ 6 7 #include "mozilla/ProfilerThreadRegistry.h" 8 9 namespace mozilla::profiler { 10 11 /* static */ 12 ThreadRegistry::RegistryContainer ThreadRegistry::sRegistryContainer; 13 14 /* static */ 15 ThreadRegistry::RegistryMutex ThreadRegistry::sRegistryMutex; 16 17 #if !defined(MOZ_GECKO_PROFILER) 18 // When MOZ_GECKO_PROFILER is not defined, the function definitions in 19 // platform.cpp are not built, causing link errors. So we keep these simple 20 // definitions here. 21 22 /* static */ Register(ThreadRegistration::OnThreadRef aOnThreadRef)23void ThreadRegistry::Register(ThreadRegistration::OnThreadRef aOnThreadRef) { 24 LockedRegistry lock; 25 MOZ_RELEASE_ASSERT(sRegistryContainer.append(OffThreadRef{aOnThreadRef})); 26 } 27 28 /* static */ Unregister(ThreadRegistration::OnThreadRef aOnThreadRef)29void ThreadRegistry::Unregister(ThreadRegistration::OnThreadRef aOnThreadRef) { 30 LockedRegistry lock; 31 for (OffThreadRef& thread : sRegistryContainer) { 32 if (thread.IsPointingAt(*aOnThreadRef.mThreadRegistration)) { 33 sRegistryContainer.erase(&thread); 34 break; 35 } 36 } 37 } 38 #endif // !defined(MOZ_GECKO_PROFILER) 39 40 } // namespace mozilla::profiler 41