Skip to content

Commit

Permalink
Merge pull request #324 from KruschenZ/AutoHotkeyL-v1.1.37.01-fixed-C…
Browse files Browse the repository at this point in the history
…ritical
  • Loading branch information
KruschenZ authored and Lexikos committed Mar 16, 2024
1 parent d2918e1 commit dd9911b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions source/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,7 @@ void InitNewThread(int aPriority, bool aSkipUninterruptible, bool aIncrementThre
if (g_script.mUninterruptibleTime && g_script.mUninterruptedLineCountMax // Both components must be non-zero to start off uninterruptible.
|| g.ThreadIsCritical) // v1.0.38.04.
{
g.PeekFrequency = UNINTERRUPTIBLE_PEEK_FREQUENCY; // This ensures the thread will always have a chance to call Critical() before MsgSleep() is called.
g.AllowThreadToBeInterrupted = false; // Fairly old comment: Use g.AllowThreadToBeInterrupted vs. g_AllowInterruption in case g_AllowInterruption just happens to have been set to true for some other reason (e.g. SendKeys()):
if (!g.ThreadIsCritical)
{
Expand Down Expand Up @@ -2282,10 +2283,14 @@ BOOL IsInterruptible()
&& g->UninterruptibleDuration > -1 // Must take precedence over the below. For backward compatibility, g_script.mUninterruptibleTime is not checked because it's supposed to go into effect during thread creation, not after the thread is running and has possibly changed the timeout via "Thread Interrupt".
&& (DWORD)(GetTickCount()- g->ThreadStartTime) >= (DWORD)g->UninterruptibleDuration // See big comment section above.
)
{
// Once the thread becomes interruptible by any means, g->ThreadStartTime/UninterruptibleDuration
// can never matter anymore because only Critical (never "Thread Interrupt") can turn off the
// interruptibility again, at which time only Critical can ever re-enable interruptibility.
g->AllowThreadToBeInterrupted = true; // Avoids issues with 49.7 day limit of 32-bit TickCount, and also helps performance future callers of this function (they can skip most of the checking above).
if (!g->ThreadIsCritical)
g->PeekFrequency = DEFAULT_PEEK_FREQUENCY;
}
//else g->AllowThreadToBeInterrupted is already up-to-date.
return (BOOL)g->AllowThreadToBeInterrupted;
}
Expand Down
3 changes: 2 additions & 1 deletion source/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,8 @@ inline void global_init(global_struct &g)
// Not sure what the optimal default is. 1 seems too low (scripts would be very slow by default):
g.LinesPerCycle = -1;
g.IntervalBeforeRest = 10; // sleep for 10ms every 10ms
#define DEFAULT_PEEK_FREQUENCY 5
#define DEFAULT_PEEK_FREQUENCY 5 // Default peek frequency for an interruptible/non-critical thread.
#define UNINTERRUPTIBLE_PEEK_FREQUENCY 16 // Used during a thread's uninterruptible period to ensure it has a chance to call Critical() before MsgSleep() is called.
g.PeekFrequency = DEFAULT_PEEK_FREQUENCY; // v1.0.46. See comments in ACT_CRITICAL.
g.AllowThreadToBeInterrupted = true; // Separate from g_AllowInterruption so that they can have independent values.
g.UninterruptibleDuration = 0; // 0 means uninterruptibility times out instantly. Some callers may want this so that this "g" can be used to launch other threads (e.g. threadless callbacks) using 0 as their default.
Expand Down
5 changes: 4 additions & 1 deletion source/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11894,7 +11894,10 @@ ResultType Line::ExecUntil(ExecUntilMode aMode, ExprTokenType *aResultToken, Lin
// THIS SECTION DOES NOT CHECK g.ThreadStartTime because that only needs to be
// checked on demand by callers of IsInterruptible().
if (g.UninterruptedLineCount > g_script.mUninterruptedLineCountMax) // See above.
{
g.AllowThreadToBeInterrupted = true;
g.PeekFrequency = DEFAULT_PEEK_FREQUENCY;
}
else
// Incrementing this unconditionally makes it a cruder measure than g.LinesPerCycle,
// but it seems okay to be less accurate for this purpose:
Expand Down Expand Up @@ -15250,7 +15253,7 @@ __forceinline ResultType Line::Perform() // As of 2/9/2009, __forceinline() redu
// DON'T GO TOO HIGH because this setting reduces response time for ALL messages, even those that
// don't launch script threads (especially painting/drawing and other screen-update events).
// Some hardware has a tickcount granularity of 15 instead of 10, so this covers more variations.
DWORD peek_frequency_when_critical_is_on = 16; // Set default. See below.
DWORD peek_frequency_when_critical_is_on = UNINTERRUPTIBLE_PEEK_FREQUENCY; // Set default. See below.
// v1.0.48: Below supports "Critical 0" as meaning "Off" to improve compatibility with A_IsCritical.
// In fact, for performance, only the following are no recognized as turning on Critical:
// - "On"
Expand Down

0 comments on commit dd9911b

Please sign in to comment.