TinyRobotics
Loading...
Searching...
No Matches
MutexRP2040.h
1#pragma once
2#include "TinyRobotics/concurrency/Mutex.h"
3
4namespace tinyrobotics {
5
6/**
7 * @brief Disable, enable interrupts (only on the actual core)
8 * @ingroup concurrency
9 * @author Phil Schatzmann
10 *
11 */
12class NoInterruptHandler : public MutexBase {
13 public:
14 void lock() override {
15 noInterrupts();
16 }
17 void unlock() override {
18 interrupts();
19 }
20};
21
22/**
23 * @brief Mutex API for non IRQ mutual exclusion between cores.
24 * Mutexes are application level locks usually used protecting data structures
25 * that might be used by multiple threads of execution. Unlike critical
26 * sections, the mutex protected code is not necessarily required/expected
27 * to complete quickly, as no other sytem wide locks are held on account of
28 * an acquired mutex.
29 * @ingroup concurrency
30 * @author Phil Schatzmann
31
32 */
33
34class MutexRP2040 : public MutexBase {
35 public:
36 MutexRP2040() {
37 mutex_init(&mtx);
38 }
39 virtual ~MutexRP2040() = default;
40
41 void lock() override {
42 mutex_enter_blocking(&mtx);
43 }
44 void unlock() override {
45 mutex_exit(&mtx);
46 }
47
48 protected:
49 mutex_t mtx;
50};
51
52/// @brief Default Mutex implementation using RP2040 Pico SDK
53/// @ingroup concurrency
54using Mutex = MutexRP2040;
55
56} // namespace audio_tools
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:34
Disable, enable interrupts (only on the actual core)
Definition: MutexRP2040.h:12