Skip to content

Wrap thread_switch in an atomic section #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2016

Conversation

niklarm
Copy link
Contributor

@niklarm niklarm commented Sep 23, 2016

The system hook thread_switch gets called both through the SVC and
though the PendSV, which can get interrupted by the SVC.
Since calls to the uVisor API are not re-entrant, we need to wrap this
function in an atomic section to prevent faults.

cc @AlessandroA @meriac @Patater

The system hook thread_switch gets called both through the SVC and 
though the PendSV, which can get interrupted by the SVC.
Since calls to the uVisor API are not re-entrant, we need to wrap this
function in an atomic section to prevent faults.
/* Wrap a function call into an atomic section with IRQ state restoration. */
#define atomic_call_wrapper(fn) { \
uint32_t primask = __get_PRIMASK(); \
__disable_irq(); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when this is called from an SVC?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case the atomic section would not be necessary, but it also doesn't do any harm.

@@ -27,6 +27,16 @@
#include "halt.h"
#include "vmpu.h"

/* Wrap a function call into an atomic section with IRQ state restoration. */
#define atomic_call_wrapper(fn) { \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AlessandroA
Copy link
Contributor

@meriac

@meriac meriac merged commit 669eda9 into ARMmbed:master Sep 26, 2016
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.

4 participants