Skip to content

Commit

Permalink
Bug 1758795 - Run cleanup registration on main thread r=TravisLong
Browse files Browse the repository at this point in the history
If we don't, we assert if the first GIFFT-enabled timing distribution's
instrumentation thread on a given process is not the main thread.

Differential Revision: https://phabricator.services.mozilla.com/D141632
  • Loading branch information
chutten committed Mar 21, 2022
1 parent 5a06728 commit b1fe227
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Jinja2 template is not. Pleas file bugs! #}
#include "nsClassHashtable.h"
#include "nsTHashMap.h"
{% endif %}
#include "nsThreadUtils.h"

#ifndef mozilla_glean_{{ probe_type }}GifftMap_h
#define mozilla_glean_{{ probe_type }}GifftMap_h
Expand All @@ -31,10 +32,12 @@ static inline TimerToStampMutex::AutoLock GetTimerIdToStartsLock() {
auto lock = sTimerIdToStarts.Lock();
if (!*lock) {
*lock = MakeUnique<nsTHashMap<TimerId, TimeStamp>>();
RunOnShutdown([&] {
auto lock = sTimerIdToStarts.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
NS_DispatchToMainThread(NS_NewRunnableFunction(__func__, [&] {
RunOnShutdown([&] {
auto lock = sTimerIdToStarts.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
}));
}
return lock;
}
Expand All @@ -49,10 +52,12 @@ static inline SubmetricToMirrorMutex::AutoLock GetLabeledMirrorLock() {
auto lock = sLabeledMirrors.Lock();
if (!*lock) {
*lock = MakeUnique<SubmetricToLabeledMirrorMapType>();
RunOnShutdown([&] {
auto lock = sLabeledMirrors.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
NS_DispatchToMainThread(NS_NewRunnableFunction(__func__, [&] {
RunOnShutdown([&] {
auto lock = sLabeledMirrors.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
}));
}
return lock;
}
Expand Down Expand Up @@ -87,10 +92,12 @@ static inline TimesToStartsMutex::AutoLock GetTimesToStartsLock() {
auto lock = sTimespanStarts.Lock();
if (!*lock) {
*lock = MakeUnique<nsTHashMap<ScalarIDHashKey, TimeStamp>>();
RunOnShutdown([&] {
auto lock = sTimespanStarts.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
NS_DispatchToMainThread(NS_NewRunnableFunction(__func__, [&] {
RunOnShutdown([&] {
auto lock = sTimespanStarts.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
}));
}
return lock;
}
Expand Down
1 change: 1 addition & 0 deletions toolkit/components/glean/tests/pytest/gifft_output_Event
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "mozilla/Maybe.h"
#include "mozilla/Telemetry.h"
#include "mozilla/DataMutex.h"
#include "nsThreadUtils.h"

#ifndef mozilla_glean_EventGifftMap_h
#define mozilla_glean_EventGifftMap_h
Expand Down
11 changes: 7 additions & 4 deletions toolkit/components/glean/tests/pytest/gifft_output_Histogram
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "mozilla/Maybe.h"
#include "mozilla/Telemetry.h"
#include "mozilla/DataMutex.h"
#include "nsThreadUtils.h"

#ifndef mozilla_glean_HistogramGifftMap_h
#define mozilla_glean_HistogramGifftMap_h
Expand All @@ -23,10 +24,12 @@ static inline TimerToStampMutex::AutoLock GetTimerIdToStartsLock() {
auto lock = sTimerIdToStarts.Lock();
if (!*lock) {
*lock = MakeUnique<nsTHashMap<TimerId, TimeStamp>>();
RunOnShutdown([&] {
auto lock = sTimerIdToStarts.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
NS_DispatchToMainThread(NS_NewRunnableFunction(__func__, [&] {
RunOnShutdown([&] {
auto lock = sTimerIdToStarts.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
}));
}
return lock;
}
Expand Down
21 changes: 13 additions & 8 deletions toolkit/components/glean/tests/pytest/gifft_output_Scalar
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mozilla/Tuple.h"
#include "nsClassHashtable.h"
#include "nsTHashMap.h"
#include "nsThreadUtils.h"

#ifndef mozilla_glean_ScalarGifftMap_h
#define mozilla_glean_ScalarGifftMap_h
Expand All @@ -29,10 +30,12 @@ static inline SubmetricToMirrorMutex::AutoLock GetLabeledMirrorLock() {
auto lock = sLabeledMirrors.Lock();
if (!*lock) {
*lock = MakeUnique<SubmetricToLabeledMirrorMapType>();
RunOnShutdown([&] {
auto lock = sLabeledMirrors.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
NS_DispatchToMainThread(NS_NewRunnableFunction(__func__, [&] {
RunOnShutdown([&] {
auto lock = sLabeledMirrors.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
}));
}
return lock;
}
Expand Down Expand Up @@ -67,10 +70,12 @@ static inline TimesToStartsMutex::AutoLock GetTimesToStartsLock() {
auto lock = sTimespanStarts.Lock();
if (!*lock) {
*lock = MakeUnique<nsTHashMap<ScalarIDHashKey, TimeStamp>>();
RunOnShutdown([&] {
auto lock = sTimespanStarts.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
NS_DispatchToMainThread(NS_NewRunnableFunction(__func__, [&] {
RunOnShutdown([&] {
auto lock = sTimespanStarts.Lock();
*lock = nullptr; // deletes, see UniquePtr.h
});
}));
}
return lock;
}
Expand Down

0 comments on commit b1fe227

Please sign in to comment.