fix wasm build. (#9312)

The new AsyncJobQueue can't work with wasm, which doesn't support 
threads.
This commit is contained in:
Mathias Agopian
2025-10-13 12:18:28 -07:00
committed by GitHub
parent ad6f6cf149
commit c79d695ffb
3 changed files with 27 additions and 0 deletions
+17
View File
@@ -26,6 +26,7 @@
namespace utils {
AsyncJobQueue::AsyncJobQueue(const char* name, Priority priority) {
#if !defined(__EMSCRIPTEN__)
mQueue.reserve(2);
mThread = std::thread([this, name, priority]() {
JobSystem::setThreadName(name);
@@ -50,13 +51,17 @@ AsyncJobQueue::AsyncJobQueue(const char* name, Priority priority) {
}
} while (!exitRequested);
});
#endif
}
AsyncJobQueue::~AsyncJobQueue() noexcept {
#if !defined(__EMSCRIPTEN__)
assert_invariant(mQueue.empty());
#endif
}
void AsyncJobQueue::push(Job&& job) {
#if !defined(__EMSCRIPTEN__)
std::unique_lock lock(mLock);
if (UTILS_UNLIKELY(mExitRequested)) {
LOG(WARNING) << "AsyncJobQueue::push() called after drainAndExit()";
@@ -67,9 +72,20 @@ void AsyncJobQueue::push(Job&& job) {
lock.unlock();
mCondition.notify_one();
}
#endif
}
bool AsyncJobQueue::isValid() const noexcept {
#if !defined(__EMSCRIPTEN__)
return mThread.joinable();
#else
return false;
#endif
}
void AsyncJobQueue::drainAndExit() {
#if !defined(__EMSCRIPTEN__)
std::unique_lock lock(mLock);
// we request the service thread to exit, but we're guaranteed that it'll only exit
// after all current callbacks are processed. In addition, once mExitRequested is set,
@@ -80,6 +96,7 @@ void AsyncJobQueue::drainAndExit() {
if (mThread.joinable()) {
mThread.join();
}
#endif
}
} // namespace utils