Disabling all interrupts (-routine-disable-interrupts
-routine-enable-interrupts
)
Specify routines that disable and reenable interrupts.
Description
This option affects a Bug Finder analysis only. The option is not available for code generated from MATLAB® code or Simulink® models.
Specify a routine that disables all tasks and interrupts other than the current one, and a routine that reenables them.
The routine that you specify for the option disables preemption by all:
Non-cyclic tasks.
Cyclic tasks.
Interrupts.
In other words, the analysis considers that the body of operations between the disabling routine and the enabling routine is atomic and not interruptible at all.
Set Option
User interface (desktop products only): In your project configuration, the option is available on the Multitasking node. See Dependencies for other options you must also enable.
User interface (Polyspace Platform, desktop products only): In your project configuration, the option is on the Static Analysis tab on the Multitasking node. See Dependencies for other options you must also enable.
Command line and options
file: Use the option
-routine-disable-interrupts
and
-routine-enable-interrupts
. See Command-Line Information.
Why Use This Option
A Bug Finder analysis uses the information when looking for data race defects. For instance,
in the following code, the function disable_all_interrupts
disables
all interrupts until the function enable_all_interrupts
is called.
Even if task
, isr1
and isr2
run
concurrently, the operations x=0
or x=1
cannot
interrupt the operation x++
. There are no data race
defects.
int x; void isr1() { x = 0; } void isr2() { x = 1; } void task() { disable_all_interrupts(); x++; enable_all_interrupts(); }
Settings
No Default
In Disabling routine, enter the routine that disables all interrupts.
In Enabling routine, enter the routine that reenables all interrupts.
Enter function names or choose from a list.
Click to add a field and enter the function name.
Click to list functions in your code. Choose functions from the list.
Dependencies
To enable this option in the user interface of the desktop products, first select the
option Configure multitasking manually
.
Tips
Protection via disabling interrupts is conceptually different from protection via critical sections.
In the Polyspace® multitasking model, to protect two sections of code from each other via critical sections, you have to embed them in the same critical section. In other words, you have to place the two sections between calls to the same lock and unlock function.
For instance, suppose you use critical sections as follows:
Here, the operationvoid isr1() { begin_critical_section(); x = 0; end_critical_section(); } void isr2() { x = 1; } void task() { begin_critical_section(); x++; end_critical_section(); }
x++
is protected from the operationx=0
inisr1
, but not from the operationx=1
inisr2
. If the functionbegin_critical_section
disabled all interrupts, calling it beforex++
would have been sufficient to protect it.Typically, you use one pair of routines in your code to disable and reenable interrupts, but you can have many pairs of lock and unlock functions that implement critical sections.
The routines that disable and enable interrupts must be functions. For instance, if you define a function-like macro:
You cannot use the macro#define disable_interrupt() interrupt_flag=0
disable_interrupt()
as routine disabling interrupts.You can use this option to make sections of nonpreemptable interrupts preemptable. To make only a section of an interrupt preemptable, call a routine enabling all interrupts before that section and call another routine disabling all interrupts after the section is complete.
For instance, if you specify the routine
isr()
as an interrupt, it is nonpreemptable by default. However, withinisr()
, if you call a routine enabling all interrupts, the section following the call is preemptable till you call another routine disabling all interrupts:void isr() { x++; //Nonpreemptable enable_all_interrupts(); //Routine enabling interrupts y++; //Preemptable disable_all_interrupts(); //Routine disabling interrupts z++; //Nonpreemptable }
Command-Line Information
Parameter: -routine-disable-interrupts | -routine-enable-interrupts |
No Default |
Value: function_name |
Example (Bug Finder):
polyspace-bug-finder -sources |
Example (Bug Finder Server):
polyspace-bug-finder-server -sources |
Version History
Introduced in R2017a