arduino-audio-tools
Loading...
Searching...
No Matches
MutexRTOS.h
1#pragma once
2#include "AudioToolsConfig.h"
3#include "AudioTools/Concurrency/Mutex.h"
4
5#ifdef ESP32
6# include "freertos/FreeRTOS.h"
7# include "freertos/semphr.h"
8#elif defined(__linux__)
9#else
10# include "FreeRTOS.h"
11# include "semphr.h"
12#endif
13
14namespace audio_tools {
15
22class MutexRTOS : public MutexBase {
23public:
24 MutexRTOS() {
25 xSemaphore = xSemaphoreCreateBinary();
26 unlock();
27 }
28 virtual ~MutexRTOS() {
29 vSemaphoreDelete(xSemaphore);
30 }
31 void lock() override {
32 xSemaphoreTake(xSemaphore, portMAX_DELAY);
33 }
34 void unlock() override {
35 xSemaphoreGive(xSemaphore);
36 }
37
38protected:
39 SemaphoreHandle_t xSemaphore = NULL;
40};
41
50public:
52 xSemaphore = xSemaphoreCreateBinary();
53 unlock();
54 }
55 virtual ~MutexRecursiveRTOS() {
56 vSemaphoreDelete(xSemaphore);
57 }
58 void lock() override {
59 xSemaphoreTakeRecursive(xSemaphore, portMAX_DELAY);
60 }
61 void unlock() override {
62 xSemaphoreGiveRecursive(xSemaphore);
63 }
64
65protected:
66 SemaphoreHandle_t xSemaphore = NULL;
67};
68
69
72using Mutex = MutexRTOS;
73
74}
Empty Mutex implementation which does nothing.
Definition Mutex.h:18
Mutex API for non IRQ mutual exclusion between cores. Mutexes are application level locks usually use...
Definition MutexRP2040.h:37
Mutex implemntation using FreeRTOS.
Definition MutexRTOS.h:22
Recursive Mutex implemntation using FreeRTOS.
Definition MutexRTOS.h:49
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10