1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #pragma once
- #include "esp_attr.h"
- #include "esp_system.h"
- #include "freertos/FreeRTOS.h"
- #include "freertos/semphr.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct LockingHandle LockingHandle;
- #ifdef __cplusplus
- }
- #include <string>
- namespace System {
- class Locking {
- private:
- SemaphoreHandle_t _mutex;
- static const int MaxDelay;
- static const int LockMaxWait;
- std::string _name;
- public:
- Locking(std::string name) : _mutex(xSemaphoreCreateRecursiveMutex()), _name(name) {}
- bool Lock(TickType_t maxWait_ms = LockMaxWait);
- void Unlock();
- bool IsLocked() { return xSemaphoreGetMutexHolder(_mutex) != nullptr; }
- ~Locking() { vSemaphoreDelete(_mutex); }
- static Locking* Create(std::string name);
- static void Destroy(Locking* lock);
- };
- }
- extern "C" {
- #endif
- LockingHandle* Locking_Create(const char* name);
- void Locking_Destroy(LockingHandle* lock);
- bool Locking_Lock(LockingHandle* lock, TickType_t maxWait_ms);
- void Locking_Unlock(LockingHandle* lock);
- bool Locking_IsLocked(LockingHandle* lock);
- #ifdef __cplusplus
- }
- #endif
|