зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1360526 - Make weak cache iteration more readable r=sfink
This commit is contained in:
Родитель
e1ab4d2be9
Коммит
9958de3edd
|
@ -5167,7 +5167,7 @@ GCRuntime::sweepJitDataOnMainThread(FreeOp* fop)
|
||||||
using WeakCacheTaskVector = mozilla::Vector<SweepWeakCacheTask, 0, SystemAllocPolicy>;
|
using WeakCacheTaskVector = mozilla::Vector<SweepWeakCacheTask, 0, SystemAllocPolicy>;
|
||||||
|
|
||||||
template <typename Functor>
|
template <typename Functor>
|
||||||
static bool
|
static inline bool
|
||||||
IterateWeakCaches(JSRuntime* rt, Functor f)
|
IterateWeakCaches(JSRuntime* rt, Functor f)
|
||||||
{
|
{
|
||||||
for (GCSweepGroupIter zone(rt); !zone.done(); zone.next()) {
|
for (GCSweepGroupIter zone(rt); !zone.done(); zone.next()) {
|
||||||
|
@ -5189,19 +5189,22 @@ static WeakCacheTaskVector
|
||||||
PrepareWeakCacheTasks(JSRuntime* rt)
|
PrepareWeakCacheTasks(JSRuntime* rt)
|
||||||
{
|
{
|
||||||
// Build a vector of sweep tasks to run on a helper thread.
|
// Build a vector of sweep tasks to run on a helper thread.
|
||||||
WeakCacheTaskVector out;
|
WeakCacheTaskVector tasks;
|
||||||
if (IterateWeakCaches(rt, [&] (JS::WeakCache<void*>* cache) {
|
bool ok = IterateWeakCaches(rt, [&] (JS::WeakCache<void*>* cache) {
|
||||||
return out.emplaceBack(rt, *cache);
|
return tasks.emplaceBack(rt, *cache);
|
||||||
})) {
|
});
|
||||||
return out;
|
|
||||||
|
// If we ran out of memory, do all the work now and ensure we return an
|
||||||
|
// empty list.
|
||||||
|
if (!ok) {
|
||||||
|
IterateWeakCaches(rt, [&] (JS::WeakCache<void*>* cache) {
|
||||||
|
SweepWeakCacheTask(rt, *cache).runFromActiveCooperatingThread(rt);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
tasks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we ran out of memory, do all the work now and return an empty list.
|
return tasks;
|
||||||
IterateWeakCaches(rt, [&] (JS::WeakCache<void*>* cache) {
|
|
||||||
SweepWeakCacheTask(rt, *cache).runFromActiveCooperatingThread(rt);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
return WeakCacheTaskVector();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Task>
|
template <typename Task>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче