Ah thank you! This is almost exactly what I need
The example uses:
void increment(void)
{
for (int i = 0; i < value; i++) {
#if (USE_CRITICAL_SECTION_LOCK == 1)
CriticalSectionLock lock; // <----HERE
#endif
counter += 1;
}
}
It works but I find it strange that you need to instantiate an object to lock a critical section. Unless you look at the implementation, there is no way to know what is does:
CriticalSectionLock::CriticalSectionLock()
{
core_util_critical_section_enter();
}
CriticalSectionLock::~CriticalSectionLock()
{
core_util_critical_section_exit();
}
I still would prefer the “standard” way:
class CircularBuffer {
public:
auto pop(T& data) -> bool
{
const std::lock_guard<mbed::CriticalSectionLock> lock(_lock);
// ...
}
private:
CriticalSectionLock _lock {};
}
If that makes sense.
It’s just a simple PR to add lock()
and unlock()
to CriticalSection