Skip to content

Commit

Permalink
Bug 1656137 - Spin-wait on completion event rather than blocking main…
Browse files Browse the repository at this point in the history
… thread. r=jya

Differential Revision: https://phabricator.services.mozilla.com/D85357
  • Loading branch information
kinetiknz committed Jul 31, 2020
1 parent 68aa4aa commit 8009935
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions dom/media/fuzz/FuzzMedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@

using namespace mozilla;

RefPtr<SharedThreadPool> sFuzzThreadPool;

class FuzzRunner {
public:
explicit FuzzRunner(Benchmark* aBenchmark) : mBenchmark(aBenchmark) {}

void Run() {
// Assert we're on the main thread, otherwise `done` must be synchronized.
MOZ_ASSERT(NS_IsMainThread());
bool done = false;

mBenchmark->Init();
media::Await(
GetMediaThreadPool(MediaThreadType::PLAYBACK), mBenchmark->Run(),
[&](uint32_t aDecodeFps) {}, [&](const MediaResult& aError) {});
mBenchmark->Run()->Then(
// Non DocGroup-version of AbstractThread::MainThread() is fine for
// testing.
AbstractThread::MainThread(), __func__,
[&](uint32_t aDecodeFps) { done = true; }, [&]() { done = true; });

// Wait until benchmark completes.
SpinEventLoopUntil([&]() { return done; });
return;
}

private:
RefPtr<Benchmark> mBenchmark;
};

static int FuzzingInitMedia(int* argc, char*** argv) {
// Grab a strong reference to the media thread pool to avoid thread
// leaks. For more information, see bug 1567170.
sFuzzThreadPool = GetMediaThreadPool(MediaThreadType::PLAYBACK);
return 0;
}

#define MOZ_MEDIA_FUZZER(_name) \
static int FuzzingRunMedia##_name(const uint8_t* data, size_t size) { \
if (!size) { \
Expand All @@ -54,8 +54,7 @@ static int FuzzingInitMedia(int* argc, char*** argv) {
runner.Run(); \
return 0; \
} \
MOZ_FUZZING_INTERFACE_RAW(FuzzingInitMedia, FuzzingRunMedia##_name, \
Media##_name);
MOZ_FUZZING_INTERFACE_RAW(nullptr, FuzzingRunMedia##_name, Media##_name);

MOZ_MEDIA_FUZZER(ADTS);
MOZ_MEDIA_FUZZER(Flac);
Expand Down

0 comments on commit 8009935

Please sign in to comment.