Skip to content

Fixes 2532 throttle trigger priority#2534

Merged
Dunbaratu merged 7 commits intoKSP-KOS:developfrom
Dunbaratu:fixes_2532_throttle_trigger_priority
Jun 16, 2019
Merged

Fixes 2532 throttle trigger priority#2534
Dunbaratu merged 7 commits intoKSP-KOS:developfrom
Dunbaratu:fixes_2532_throttle_trigger_priority

Conversation

@Dunbaratu
Copy link
Member

@Dunbaratu Dunbaratu commented Jun 5, 2019

Fixes #2532

Essentially the earlier InterruptPriority system still wasn't fully implemented properly, and still had some messy unnecessarily clunky code in ContinueExecution() that was trying to handle the different types of trigger with special cases (instead of just using the priority level numerically and ignoring all else).

This fix does the following:

1 - Adds a new higher level priority - level 30 - for use with cooked control locks. They now enjoy the highest priority and will interrupt anything other than another cooked control lock.

2 - Removes some ugly code from CPU.ContinueExecution() that pre-dated the concept of InterruptPriority. (It tried to accomplish some of the same ideas but in a more complex special case kind of way). That code was actually interfering with interrupt priorities working properly. (It had to be removed in order to make priority level 30 actually succeed at interrupting level 20.)

3 - Some of the removed code mentioned above was present to attempt to support GUI callbacks interrupting other GUI callbacks just in case a GUI callback fired off something that lasts a long time so it would't freeze the rest of the GUI while it runs. (Normally a trigger doesn't interrupt a trigger of the same priority so this was meant to be a special case just for GUI callbacks). In testing I found out that this had never been working anyway, and even with that messy code there, GUI callbacks still wouldn't interrupt other GUI callbacks so the reason for that was moot anyway. From a backward-compatibilitly point of view it didn't have to be supported.

4 - Just in case someone does want to use a design pattern where one GUI callback lasts a long time and lets other GUI callbacks interrupt it, I provied a new built-in function, DROPPRIORITY that can be executed from inside a trigger to drop the priority back down to what it was prior to the interruption. Thus the trigger can say "go ahead and re-enable interruptions and allow myself to get interrupted".

(The example program written in the docs shows a case of how things differ when DROPPRIORITY is present.)

I struggle with whether or not bullet point (4) should be described well in the docs, or should be hidden so only people who read the long CPU_hardware page see it. (so it can't be used by someone who's never looked at the section on priorities and doesn't understand the consequences).

Dunbaratu added 7 commits May 25, 2019 05:16
Added a case in BreakExecution() to protect itself if it gets
called while there are no program contexts existing yet, and
thus nothing for it *to* break.  (So it doesn't crash if you
call it while the CPU is powered down.)
(The difference is that DROPPRIORITY only lets you
drop to whatever the level was that called you,
not all the way to Normal if you weren't called from
Normal.)
That's how it used to work, when it was called ALLOWINTERRUPT(),
but the decision to only let it drop one level of prioirty means
the docs had to be changed to match.
@Dunbaratu Dunbaratu merged commit 861e41f into KSP-KOS:develop Jun 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue 2130 back again. Throttle won't update until after a trigger.

1 participant