#include // WASI (single-threaded) replacement for s/Thread.cpp #include "../runtime/Runtime.h" #include namespace s { class Thread : public runtime::Object {}; class Mutex : public runtime::Object {}; // No real threads: run the closure synchronously at creation time. extern "C" Thread* sThreadNew(void *fn, void *capture) { runtime::Callable callable; void *parts[2] = {fn, capture}; std::memcpy(&callable, parts, sizeof(parts)); auto thread = Thread::init(); callable.retain(); callable(); callable.release(); return thread; } extern "C" void sThreadJoin(Thread *) {} extern "C" void sThreadDestruct(Thread *thread) { thread->~Thread(); } extern "C" void sThreadDelay(runtime::ClassInfo *, runtime::Integer mcs) { struct timespec ts{ (time_t)(mcs / 1000000), (long)((mcs % 1000000) * 1000) }; nanosleep(&ts, nullptr); } extern "C" Mutex* sMutexNew() { return Mutex::init(); } extern "C" void sMutexLock(Mutex *) {} extern "C" void sMutexTryLock(Mutex *) {} extern "C" void sMutexUnlock(Mutex *) {} extern "C" void sMutexDestruct(Mutex *mutex) { mutex->~Mutex(); } } SET_INFO_FOR(s::Thread, s, 1f9f5) SET_INFO_FOR(s::Mutex, s, 1f510)