Skip to content
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

PX4: Add support for CONFIG_SMP=y (NuttX only) #827

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
px4_atomic: Support for CONFIG_SMP=y
Use spinlock as the kernel side lock
pussuw committed Dec 9, 2024
commit d8fc3e1a200c15dc76c6984ecb892721c27814ca
Original file line number Diff line number Diff line change
@@ -33,9 +33,12 @@

#pragma once

#include <nuttx/config.h>

#include <stdint.h>

#include <nuttx/irq.h>
#include <nuttx/spinlock.h>

#include <px4_platform_common/sem.h>

@@ -54,6 +57,9 @@ class atomic_block
px4_sem_t _lock;
irqstate_t _irqlock;
};
#ifdef CONFIG_SMP
spinlock_t _spinlock;
#endif
};

}
11 changes: 11 additions & 0 deletions platforms/nuttx/src/px4/common/px4_atomic.cpp
Original file line number Diff line number Diff line change
@@ -39,6 +39,9 @@ namespace px4
atomic_block::atomic_block(void)
{
_irqlock = 0;
#ifdef CONFIG_SMP
_spinlock = SP_UNLOCKED;
#endif
}

atomic_block::~atomic_block(void)
@@ -48,12 +51,20 @@ atomic_block::~atomic_block(void)

void atomic_block::start(void)
{
#ifdef CONFIG_SMP
_irqlock = spin_lock_irqsave_wo_note(&_spinlock);
#else
_irqlock = enter_critical_section();
#endif
}

void atomic_block::finish(void)
{
#ifdef CONFIG_SMP
spin_unlock_irqrestore_wo_note(&_spinlock, _irqlock);
#else
leave_critical_section(_irqlock);
#endif
}

}