diff options
author | Nick Brassel <[email protected]> | 2023-12-21 09:32:19 +1100 |
---|---|---|
committer | GitHub <[email protected]> | 2023-12-21 09:32:19 +1100 |
commit | 2661ee282a7edfdff299d2ccfc298dac75cf65e4 (patch) | |
tree | 8675ab8c6c294d2c5d12b8d9a533c77c88f85c33 /quantum | |
parent | 3afa2a9439a74c4f4d906dcb1dfa975f13fc6763 (diff) | |
download | qmk_firmware-2661ee282a7edfdff299d2ccfc298dac75cf65e4.tar.gz qmk_firmware-2661ee282a7edfdff299d2ccfc298dac75cf65e4.zip |
[Bugfix] Manipulate deferred executor slot only if tokens match (#22722)0.23.2
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/deferred_exec.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/quantum/deferred_exec.c b/quantum/deferred_exec.c index a0046a9648..b3be3747d4 100644 --- a/quantum/deferred_exec.c +++ b/quantum/deferred_exec.c @@ -124,13 +124,19 @@ void deferred_exec_advanced_task(deferred_executor_t *table, size_t table_count, // Run through each of the executors for (int i = 0; i < table_count; ++i) { - deferred_executor_t *entry = &table[i]; + deferred_executor_t *entry = &table[i]; + deferred_token curr_token = entry->token; // Check if we're supposed to execute this entry - if (entry->token != INVALID_DEFERRED_TOKEN && ((int32_t)TIMER_DIFF_32(entry->trigger_time, now)) <= 0) { + if (curr_token != INVALID_DEFERRED_TOKEN && ((int32_t)TIMER_DIFF_32(entry->trigger_time, now)) <= 0) { // Invoke the callback and work work out if we should be requeued uint32_t delay_ms = entry->callback(entry->trigger_time, entry->cb_arg); + // If the token has changed, then the callback has canceled and re-queued. Skip further processing. + if (entry->token != curr_token) { + continue; + } + // Update the trigger time if we have to repeat, otherwise clear it out if (delay_ms > 0) { // Intentionally add just the delay to the existing trigger time -- this ensures the next |