MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / ChangePauseState

Method ChangePauseState

source/script.cpp:12481–12513  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12479
12480
12481ResultType Line::ChangePauseState(LPTSTR aChangeTo)
12482// Currently designed to be called only by the Pause command (ACT_PAUSE).
12483// Returns OK or FAIL.
12484{
12485 auto toggle = Convert10Toggle(ARG1);
12486 switch (toggle)
12487 {
12488 case NEUTRAL:
12489 return PauseCurrentThread();
12490 case TOGGLE:
12491 // Update for v2: "Pause -1" is more useful if it always applies to the thread immediately beneath
12492 // the current thread, since pausing the current thread would prevent a hotkey from unpausing itself
12493 // by default (there's no longer a special case allowing Pause hotkeys a second thread).
12494 if (g > g_array && g[-1].IsPaused) // Checking g>g_array avoids any chance of underflow, which might otherwise happen if this is called by the AutoExec section or a threadless callback running in thread #0.
12495 toggle = TOGGLED_OFF;
12496 // Fall through:
12497 case TOGGLED_ON:
12498 case TOGGLED_OFF:
12499 // v1.0.37.06: The old method was to unpause the the nearest paused thread on the call stack;
12500 // but it was flawed because if the thread that made the flag true is interrupted, and the new
12501 // thread is paused via the pause command, and that thread is then interrupted, when the paused
12502 // thread resumes it would automatically and wrongly be unpaused (i.e. the unpause ticket would
12503 // be used at a level higher in the call stack than intended).
12504 // Flag this thread so that when it ends, the thread beneath it will be unpaused. If that thread
12505 // (which can be the idle thread) isn't paused the following flag-change will be ignored at a later
12506 // stage. This method also relies on the fact that the current thread cannot itself be paused right
12507 // now because it is what got us here.
12508 PauseUnderlyingThread(toggle != TOGGLED_OFF); // i.e. pause if ON or fell through from TOGGLE.
12509 return OK;
12510 default: // TOGGLE_INVALID or some other disallowed value.
12511 return LineError(ERR_PARAM1_INVALID, FAIL_OR_OK, aChangeTo);
12512 }
12513}
12514
12515
12516

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected