halx
読み取り中…
検索中…
一致する文字列を見つけられません
include
halx
rtos
semaphore.hpp
[詳解]
1
#pragma once
2
3
#include <cstdint>
4
#include <memory>
5
#include <type_traits>
6
7
#include <cmsis_os2.h>
8
9
namespace
halx::rtos
{
10
11
class
Semaphore
{
12
private
:
13
struct
Deleter {
14
void
operator()(osSemaphoreId_t queue_id) { osSemaphoreDelete(queue_id); }
15
};
16
17
using
SemaphoreId =
18
std::unique_ptr<std::remove_pointer_t<osSemaphoreId_t>, Deleter>;
19
20
public
:
21
Semaphore
(uint32_t max, uint32_t initial, uint32_t attr_bits = 0) {
22
osSemaphoreAttr_t attr{};
23
attr.attr_bits = attr_bits;
24
semaphore_id_ = SemaphoreId{osSemaphoreNew(max, initial, &attr)};
25
}
26
27
bool
acquire
(uint32_t timeout) {
28
return
osSemaphoreAcquire(semaphore_id_.get(), timeout) == osOK;
29
}
30
31
void
acquire
() {
acquire
(osWaitForever); }
32
33
void
release
() { osSemaphoreRelease(semaphore_id_.get()); }
34
35
private
:
36
SemaphoreId semaphore_id_;
37
};
38
39
}
// namespace halx::rtos
halx::rtos::Semaphore::acquire
void acquire()
Definition
semaphore.hpp:31
halx::rtos::Semaphore::release
void release()
Definition
semaphore.hpp:33
halx::rtos::Semaphore::Semaphore
Semaphore(uint32_t max, uint32_t initial, uint32_t attr_bits=0)
Definition
semaphore.hpp:21
halx::rtos::Semaphore::acquire
bool acquire(uint32_t timeout)
Definition
semaphore.hpp:27
halx::rtos
Definition
mutex.hpp:9
構築:
1.13.2