move static thread declaration, recompile test and test --> worked.

This commit is contained in:
msqr1
2024-01-31 21:17:28 -08:00
parent 94a8a68170
commit 1b74781a9d
9 changed files with 192 additions and 220 deletions

View File

@@ -1,5 +1,5 @@
#include "global.h"
static pthread_t selfTID{pthread_self()};
void throwJS(const char* msg, bool err) {
EM_ASM({
if($1) {
@@ -11,24 +11,25 @@ void throwJS(const char* msg, bool err) {
}
void fireEv(const char *type, const char *content, int index) {
static ProxyingQueue pq{};
static pthread_t selfTID{pthread_self()};
static auto proxy{[index, type, content](){
auto proxy{[index, type, content](){
EM_ASM({
console.log(objs[$0]);
objs[$0].dispatchEvent(new CustomEvent(UTF8ToString($1), {"detail" : UTF8ToString($2)}))
console.log("Event type ", UTF8ToString($1), ", content " , UTF8ToString($2), ", sending to ", objs[$0]);
objs[$0].dispatchEvent(new CustomEvent(UTF8ToString($1), {"detail" : UTF8ToString($2)}));
},index, type, content);
}};
if(selfTID == pthread_self()) {
emscripten_console_log("Self dispatch");
proxy();
return;
}
emscripten_console_log("Thread dispatch");
pq.proxySync(selfTID, proxy);
}
int main() {
//vosk_set_log_level(-1);
std::thread t{[](){
wasmfs_create_directory("/opfs",0777,wasmfs_create_opfs_backend());
wasmfs_create_directory("/opfs", 0777, wasmfs_create_opfs_backend());
}};
t.detach();
emscripten_exit_with_live_runtime();