1 /* -*- Mode: C++; tab-width: 2; 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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef CALLBACKTHREADREGISTRY_H
8 #define CALLBACKTHREADREGISTRY_H
11 #include <mozilla/DataMutex.h>
14 #include <GeckoProfiler.h>
18 // This class is a singleton that tracks various callback threads and makes
19 // sure they are registered or unregistered to the profiler safely and
22 // Register and Unregister are fairly expensive and shouldn't be used in a hot
24 class CallbackThreadRegistry final
{
26 CallbackThreadRegistry();
28 ~CallbackThreadRegistry() {
29 // It would be nice to be able to assert that all threads have been
30 // unregistered, but we can't: it's legal to suspend an audio stream, so
31 // that the callback isn't called, and then immediately destroy it.
34 CallbackThreadRegistry(const CallbackThreadRegistry
&) = delete;
35 CallbackThreadRegistry
& operator=(const CallbackThreadRegistry
&) = delete;
36 CallbackThreadRegistry(CallbackThreadRegistry
&&) = delete;
37 CallbackThreadRegistry
& operator=(CallbackThreadRegistry
&&) = delete;
39 // Returns the global instance of CallbackThreadRegistry. Safe from all
41 static CallbackThreadRegistry
* Get();
43 // This is intended to be called in the first callback of a callback
45 void Register(ProfilerThreadId aThreadId
, const char* aName
);
47 // This is intended to be called when an object stops an audio callback thread
48 void Unregister(ProfilerThreadId aThreadId
);
51 struct ThreadUserCount
{
52 ProfilerThreadId mId
; // from profiler_current_thread_id
55 DataMutex
<nsTArray
<ThreadUserCount
>> mThreadIds
;
58 } // namespace mozilla
60 #endif // CALLBACKTHREADREGISTRY_H