add a Lock, LockGuard and printThreadInfo
* `Lock`: trivial wrapper for FreeRTOS binary semaphores * `LockGuard`: RAII wrapper for using `Lock` * `printThreadInfo`: helper for showing which core/FreeRTOS task we are running under
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <FreeRTOS/FreeRTOS.h>
|
||||
#include <FreeRTOS/semphr.h>
|
||||
|
||||
namespace meshtastic
|
||||
{
|
||||
|
||||
// Simple wrapper around FreeRTOS API for implementing a mutex lock.
|
||||
class Lock
|
||||
{
|
||||
public:
|
||||
Lock();
|
||||
|
||||
Lock(const Lock&) = delete;
|
||||
Lock& operator=(const Lock&) = delete;
|
||||
|
||||
/// Locks the lock.
|
||||
//
|
||||
// Must not be called from an ISR.
|
||||
void lock();
|
||||
|
||||
// Unlocks the lock.
|
||||
//
|
||||
// Must not be called from an ISR.
|
||||
void unlock();
|
||||
|
||||
private:
|
||||
SemaphoreHandle_t handle;
|
||||
};
|
||||
|
||||
// RAII lock guard.
|
||||
class LockGuard
|
||||
{
|
||||
public:
|
||||
LockGuard(Lock *lock);
|
||||
~LockGuard();
|
||||
|
||||
LockGuard(const LockGuard&) = delete;
|
||||
LockGuard& operator=(const LockGuard&) = delete;
|
||||
|
||||
private:
|
||||
Lock* lock;
|
||||
};
|
||||
|
||||
|
||||
} // namespace meshtastic
|
||||
Reference in New Issue
Block a user