| 68 | } |
| 69 | |
| 70 | void ScriptRunner::run(void) |
| 71 | { |
| 72 | // Runs on the worker thread. Drop below the main thread first so a script |
| 73 | // that never yields its core (a pure compute loop) can't starve the loop |
| 74 | // that samples hold-B and raises the abort — see ckpt_script_lower_priority. |
| 75 | ckpt_script_lower_priority(); |
| 76 | |
| 77 | ScriptEngine::Outcome out = ScriptEngine::run(mPath, {mTitleIdHex}); |
| 78 | // The run is over whatever the exit path was (return, exit(), parse-error |
| 79 | // longjmp): reclaim any archive handles the script left open, and the |
| 80 | // native memory it (or the bindings) allocated on its behalf. Only a normal |
| 81 | // return runs the script's own free() calls, so this is the only reclaim |
| 82 | // that covers an abort — see scriptheap.hpp. |
| 83 | ckpt_sav_close_all(); |
| 84 | ScriptHeap::get().releaseAll(); |
| 85 | { |
| 86 | std::lock_guard<std::mutex> lock(mMutex); |
| 87 | // A script may still finish cleanly in the window before the abort |
| 88 | // hook fires; a zero exit is reported as success, not as an abort. |
| 89 | const bool cancelled = ckpt_script_abort_requested() != 0 && out.exitValue != 0; |
| 90 | mOutcome = Outcome{mName, out.exitValue, std::move(out.output), cancelled}; |
| 91 | // Publish Done under the same lock shutdown() evaluates its predicate |
| 92 | // under, or a store landing between that check and the wait would be |
| 93 | // missed and teardown would block forever. |
| 94 | mState.store(State::Done); |
| 95 | } |
| 96 | mDoneCv.notify_all(); |
| 97 | } |
| 98 | |
| 99 | void ScriptRunner::requestCancel(void) |
| 100 | { |
no test coverage detected