diff --git a/byond-extools/src/core/various_testing.cpp b/byond-extools/src/core/various_testing.cpp index f5a1f31e..5c170461 100644 --- a/byond-extools/src/core/various_testing.cpp +++ b/byond-extools/src/core/various_testing.cpp @@ -64,7 +64,7 @@ void init_testing() { Core::enable_profiling(); debugger_initialize(); - bool find_unknowns = true; + bool find_unknowns = false; if (find_unknowns) { std::ofstream log("unknown_opcodes.txt"); diff --git a/byond-extools/src/tffi/tffi.cpp b/byond-extools/src/tffi/tffi.cpp index 1049e74f..8402ba5b 100644 --- a/byond-extools/src/tffi/tffi.cpp +++ b/byond-extools/src/tffi/tffi.cpp @@ -3,6 +3,9 @@ #include "../dmdism/disassembly.h" #include "../dmdism/opcodes.h" +#include +#include + typedef const char* (byond_ffi_func)(int, const char**); std::map suspended_procs; @@ -12,6 +15,9 @@ std::uint32_t result_string_id = 0; std::uint32_t completed_string_id = 0; std::uint32_t internal_id_string_id = 0; +std::condition_variable unsuspend_ready_cv; +std::mutex unsuspend_ready_mutex; + void tffi_suspend(ExecutionContext* ctx) { ctx->current_opcode++; @@ -19,7 +25,9 @@ void tffi_suspend(ExecutionContext* ctx) proc->time_to_resume = 0x7FFFFF; StartTiming(proc); float promise_id = ctx->constants->args[1].valuef; + std::lock_guard lk(unsuspend_ready_mutex); suspended_procs[promise_id] = proc; + unsuspend_ready_cv.notify_all(); ctx->current_opcode--; } @@ -48,19 +56,8 @@ void ffi_thread(byond_ffi_func* proc, int promise_id, int n_args, std::vector lk(unsuspend_ready_mutex); + unsuspend_ready_cv.wait(lk, [internal_id] { return suspended_procs.find(internal_id) != suspended_procs.end(); }); suspended_procs[internal_id]->time_to_resume = 1; suspended_procs.erase(internal_id); }