Fix await issue. But it doesn't work tho.

This commit is contained in:
msqr1
2024-02-08 20:19:38 -08:00
parent 5228c666a2
commit 18de98dd3b
12 changed files with 122 additions and 5988 deletions

View File

@@ -3,8 +3,8 @@
pthread_t dstThrd{pthread_self()};
std::error_code tank{};
bool OPFSOk{};
bool OPFSTried{};
ProxyingQueue glbQ{};
void fireEv(const char *type, const char *content, int index) {
auto proxy{[index, type, content](){
EM_ASM({
@@ -17,31 +17,23 @@ void fireEv(const char *type, const char *content, int index) {
}
glbQ.proxySync(dstThrd, proxy);
}
void reusableThrd::addTask(std::function<void()> task) {
void reusableThrd::addTask(std::function<void()>&& task) {
static std::thread thrd{[this](){
pthread_detach(pthread_self());
while(!done.test()) {
blocker.wait(done.test(std::memory_order_relaxed) || queue.empty(), std::memory_order_relaxed);
blocker.clear(std::memory_order_relaxed);
while(!queue.empty()) {
queue.front()();
queue.pop();
}
blocker.wait(done.test(std::memory_order_relaxed) || queue.empty(), std::memory_order_relaxed);
blocker.clear(std::memory_order_relaxed);
}
}};
thrd.detach();
queue.emplace(std::move(task));
queue.emplace(task);
blocker.test_and_set(std::memory_order_relaxed);
blocker.notify_one();
}
reusableThrd::~reusableThrd() {
done.test_and_set(std::memory_order_relaxed);
done.notify_one();
}
int main() {
std::thread t{[](){
OPFSOk = wasmfs_create_directory("/opfs", 0777, wasmfs_create_opfs_backend()) == 0;
}};
t.detach();
emscripten_exit_with_live_runtime();
}