Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / tools / profiler / public / ProfilerThreadSleep.h
blob730176d39f799ec894bbf0eefa04f7bb1a23c2ec
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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // APIs that inform the profiler when a thread is effectively asleep so that we
8 // can avoid sampling it more than once.
10 #ifndef ProfilerThreadSleep_h
11 #define ProfilerThreadSleep_h
13 #ifndef MOZ_GECKO_PROFILER
15 // This file can be #included unconditionally. However, everything within this
16 // file must be guarded by a #ifdef MOZ_GECKO_PROFILER, *except* for the
17 // following macros and functions, which encapsulate the most common operations
18 // and thus avoid the need for many #ifdefs.
20 # define AUTO_PROFILER_THREAD_SLEEP
22 static inline void profiler_thread_sleep() {}
24 static inline void profiler_thread_wake() {}
26 #else // !MOZ_GECKO_PROFILER
28 # include "mozilla/Attributes.h"
29 # include "mozilla/BaseProfilerRAIIMacro.h"
31 // These functions tell the profiler that a thread went to sleep so that we can
32 // avoid sampling it more than once while it's sleeping. Calling
33 // profiler_thread_sleep() twice without an intervening profiler_thread_wake()
34 // is an error. All three functions operate the same whether the profiler is
35 // active or inactive.
36 void profiler_thread_sleep();
37 void profiler_thread_wake();
39 // Mark a thread as asleep within a scope.
40 // (See also AUTO_PROFILER_THREAD_WAKE in ProfilerThreadState.h)
41 # define AUTO_PROFILER_THREAD_SLEEP \
42 mozilla::AutoProfilerThreadSleep PROFILER_RAII
44 namespace mozilla {
46 // (See also AutoProfilerThreadWake in ProfilerThreadState.h)
47 class MOZ_RAII AutoProfilerThreadSleep {
48 public:
49 explicit AutoProfilerThreadSleep() { profiler_thread_sleep(); }
51 ~AutoProfilerThreadSleep() { profiler_thread_wake(); }
54 } // namespace mozilla
56 #endif // !MOZ_GECKO_PROFILER
58 #endif // ProfilerThreadSleep_h