tutrcos
読み取り中…
検索中…
一致する文字列を見つけられません
include
tutrcos
core
mutex.hpp
[詳解]
1
#pragma once
2
3
#include <cstdint>
4
#include <memory>
5
#include <type_traits>
6
7
#include "cmsis_os2.h"
8
9
namespace
tutrcos
{
10
namespace
core {
11
12
class
Mutex
{
13
private
:
14
struct
Deleter {
15
void
operator()(osMutexId_t mutex_id) { osMutexDelete(mutex_id); }
16
};
17
18
using
MutexId = std::unique_ptr<std::remove_pointer_t<osMutexId_t>, Deleter>;
19
20
public
:
21
Mutex
() {
22
osMutexAttr_t attr = {};
23
attr.attr_bits = osMutexPrioInherit;
24
mutex_id_ = MutexId{osMutexNew(&attr)};
25
}
26
27
bool
try_lock
(uint32_t timeout) {
28
return
osMutexAcquire(mutex_id_.get(), timeout) == osOK;
29
}
30
31
void
lock
() {
try_lock
(osWaitForever); }
32
33
void
unlock
() { osMutexRelease(mutex_id_.get()); }
34
35
private
:
36
MutexId mutex_id_;
37
};
38
39
}
// namespace core
40
}
// namespace tutrcos
tutrcos::core::Mutex
Definition
mutex.hpp:12
tutrcos::core::Mutex::lock
void lock()
Definition
mutex.hpp:31
tutrcos::core::Mutex::Mutex
Mutex()
Definition
mutex.hpp:21
tutrcos::core::Mutex::try_lock
bool try_lock(uint32_t timeout)
Definition
mutex.hpp:27
tutrcos::core::Mutex::unlock
void unlock()
Definition
mutex.hpp:33
tutrcos
Definition
kernel.hpp:7
構築:
1.12.0