-
Notifications
You must be signed in to change notification settings - Fork 17
Implement interrupt enable/disable as a counting semaphore #16
Comments
yes, this is useful. shouldn't you be using ei_counting() for enable_interrupts() (as in the following)?
|
@rgrover |
If |
Noted/updated |
how about renaming enable_interrupts as critical_section_abort()? and dropping disable_interrupts entirely? |
+1 |
Maybe That being said, I prefer having consistent naming across the API. Maybe the right choice is: void critical_section_abort() {
__disable_interrupts();
interruptEnableCounter = 0;
__enable_interrupts();
}
void enable_interrupts() {
critical_section_abort();
} |
I'm confused what cases you would use this in I guess. Of the two mentioned, only early boot code makes sense to me (but that can call _enable_interrupts directly and the docs for critical_section* can specify that these APIs are only for use after early boot has completed). You're right that abort isn't the right name... it implies some kind of transactional semantics. What use-cases are there to abort/reset/get-out-of a critical section, that aren't fatal bugs? If code thinks it needs to do something atomically, and somewhere (nested inside) it can have interrupts re-enabled without knowing, you have a bug. |
I think that it only matters in fault handlers and init code, both of which can use If any fault handlers require interrupts to be turned on and then use any library functions which, in turn, call I can imagine this sort of feature being needed in order to dump diagnostics over a network, etc. |
Normally diagnostics would be dumped to the network after a reboot, and normally after a fatal error, any library functions are no longer safe to use (any global state, including the allocator, can't be trusted after a fatal error). |
I know that is the normal state; what I didn't know is whether we would try to do something more creative or not--a sort of partial reset, if you will. Barring that use case, I don't think there's a call for |
Everywhere that we use
__disable_interrupts
and__enable_interrupts
, we need to store the priority mask and check it later. It might be better to provide a standard API for this kind of task.A nice abstraction to use in this sort of situation is a counting enable/disable. Each time disable is called, it increments a global counter. Each time enable is called, it decrements the counter, only enabling interrupts when the counter reaches 0.
These operations need not be atomic, since they disable interrupts.
Here is a sample implementation:
The text was updated successfully, but these errors were encountered: