Nested spin_lock_irqsave

If the code is below

void test(void) { spin_lock_irqsave(&lock1, flag); ... func1(); ... spin_unlock_irqrestore(&lock1, flag); } void func1(void) { spin_lock_irqsave(&lock2, flag); ... spin_unlock_irqrestore(&lock2, flag); } 

Will there be any problems with the code? when spin_unlock_irqrestore is called in func1, will the interrupt already be enabled? What I want to achieve is the test() routine can be executed without interruption by the scheduler or interrupts. Many thanks

+6
source share
1 answer

As far as I found in the documentation, and I have not completely exhausted my search, flag save the state of bits that set different flags, and then disable interrupts, and then restore their end. If interrupts were disabled by the first call to test , and then you make another call, I would assume (and it doesn't indicate anything that I found) that it will leave interrupts off, keep flags and restore them inside func() , and then restore them back to the flag state in test .

Interrupts should be re-enabled after the test function.

I would say that your only catch is that you cannot use the same flag variable in both functions, otherwise you will overwrite the first one in your internal call and then reset, and if any flags have changed between your calls You can reset the external to the wrong state.

+6
source

Source: https://habr.com/ru/post/926213/


All Articles