Bug 1464506 - profiler_features_if_active{,_and_unpaused}() returns all features bits - r=canaltinova

Some functions may want to examine more than one feature at once, these function return everything (if the profiler is active, and optionally unpaused) so that only one call is needed.

Differential Revision: https://phabricator.services.mozilla.com/D76280
This commit is contained in:
Gerald Squelart 2020-05-25 08:57:56 +00:00
parent 271f2b32ae
commit 1c13f92ad4

View File

@ -237,6 +237,22 @@ class RacyFeatures {
static void SetUnpaused() { sActiveAndFeatures &= ~Paused; } static void SetUnpaused() { sActiveAndFeatures &= ~Paused; }
static mozilla::Maybe<uint32_t> FeaturesIfActive() {
if (uint32_t af = sActiveAndFeatures; af & Active) {
// Active, remove the Active&Paused bits to get all features.
return Some(af & ~(Active | Paused));
}
return Nothing();
}
static mozilla::Maybe<uint32_t> FeaturesIfActiveAndUnpaused() {
if (uint32_t af = sActiveAndFeatures; (af & (Active | Paused)) == Active) {
// Active but not paused, remove the Active bit to get all features.
return Some(af & ~Active);
}
return Nothing();
}
static bool IsActive() { return uint32_t(sActiveAndFeatures) & Active; } static bool IsActive() { return uint32_t(sActiveAndFeatures) & Active; }
static bool IsActiveWithFeature(uint32_t aFeature) { static bool IsActiveWithFeature(uint32_t aFeature) {
@ -531,6 +547,20 @@ bool profiler_thread_is_sleeping();
// not. // not.
uint32_t profiler_get_available_features(); uint32_t profiler_get_available_features();
// Returns the full feature set if the profiler is active.
// Note: the return value can become immediately out-of-date, much like the
// return value of profiler_is_active().
inline mozilla::Maybe<uint32_t> profiler_features_if_active() {
return mozilla::profiler::detail::RacyFeatures::FeaturesIfActive();
}
// Returns the full feature set if the profiler is active and unpaused.
// Note: the return value can become immediately out-of-date, much like the
// return value of profiler_is_active().
inline mozilla::Maybe<uint32_t> profiler_features_if_active_and_unpaused() {
return mozilla::profiler::detail::RacyFeatures::FeaturesIfActiveAndUnpaused();
}
// Check if a profiler feature (specified via the ProfilerFeature type) is // Check if a profiler feature (specified via the ProfilerFeature type) is
// active. Returns false if the profiler is inactive. Note: the return value // active. Returns false if the profiler is inactive. Note: the return value
// can become immediately out-of-date, much like the return value of // can become immediately out-of-date, much like the return value of