JS Optimization
This commit is contained in:
@@ -1,40 +1,47 @@
|
||||
#include "global.h"
|
||||
|
||||
pthread_t dstThrd{pthread_self()};
|
||||
std::error_code tank{};
|
||||
bool OPFSOk{};
|
||||
ProxyingQueue glbQ{};
|
||||
|
||||
void fireEv(const char *type, const char *content, int index) {
|
||||
static ProxyingQueue pq{};
|
||||
auto proxy{[index, type, content](){
|
||||
EM_ASM({
|
||||
objs[$0].dispatchEvent(new CustomEvent(UTF8ToString($1), {"detail" : UTF8ToString($2)}));
|
||||
},index, type, content);
|
||||
}};
|
||||
if(selfTID == pthread_self()) {
|
||||
if(dstThrd == pthread_self()) {
|
||||
proxy();
|
||||
return;
|
||||
}
|
||||
pq.proxySync(selfTID, proxy);
|
||||
glbQ.proxySync(dstThrd, proxy);
|
||||
}
|
||||
int main() {
|
||||
std::thread t{[](){
|
||||
OPFSOk = (wasmfs_create_directory("/opfs", 0777, wasmfs_create_opfs_backend()) == 0 ? true : false);
|
||||
}};
|
||||
t.detach();
|
||||
emscripten_exit_with_live_runtime();
|
||||
}
|
||||
ProxyingQueue reusableThrd::pq{};
|
||||
reusableThrd::reusableThrd() {
|
||||
thrd = std::thread{[this](){
|
||||
|
||||
void reusableThrd::addTask(std::function<void()> task) {
|
||||
static std::thread thrd{[this](){
|
||||
while(!done.test()) {
|
||||
static ProxyingQueue pq{};
|
||||
pq.execute();
|
||||
blocker.wait(done.test(), 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();
|
||||
}
|
||||
void reusableThrd::addTask(std::function<void()> task) {
|
||||
pq.proxyAsync(thrd.native_handle(), std::move(task));
|
||||
queue.emplace(std::move(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();
|
||||
}
|
||||
Reference in New Issue
Block a user