stm32rcos
読み取り中…
検索中…
一致する文字列を見つけられません
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
stm32rcos
{
10
namespace
core
{
11
12
class
Semaphore
{
13
private
:
14
struct
Deleter {
15
void
operator()(osSemaphoreId_t queue_id) { osSemaphoreDelete(queue_id); }
16
};
17
18
using
SemaphoreId =
19
std::unique_ptr<std::remove_pointer_t<osSemaphoreId_t>, Deleter>;
20
21
public
:
22
Semaphore
(uint32_t max, uint32_t initial, uint32_t attr_bits = 0) {
23
osSemaphoreAttr_t attr{};
24
attr.attr_bits = attr_bits;
25
semaphore_id_ = SemaphoreId{osSemaphoreNew(max, initial, &attr)};
26
}
27
28
bool
try_acquire
(uint32_t timeout) {
29
return
osSemaphoreAcquire(semaphore_id_.get(), timeout) == osOK;
30
}
31
32
void
acquire
() {
try_acquire
(osWaitForever); }
33
34
void
release
() { osSemaphoreRelease(semaphore_id_.get()); }
35
36
private
:
37
SemaphoreId semaphore_id_;
38
};
39
40
}
// namespace core
41
}
// namespace stm32rcos
stm32rcos::core::Semaphore::try_acquire
bool try_acquire(uint32_t timeout)
Definition
semaphore.hpp:28
stm32rcos::core::Semaphore::acquire
void acquire()
Definition
semaphore.hpp:32
stm32rcos::core::Semaphore::Semaphore
Semaphore(uint32_t max, uint32_t initial, uint32_t attr_bits=0)
Definition
semaphore.hpp:22
stm32rcos::core::Semaphore::release
void release()
Definition
semaphore.hpp:34
stm32rcos::core
Definition
mutex.hpp:10
stm32rcos
Definition
mutex.hpp:9
include
stm32rcos
core
semaphore.hpp
構築:
1.13.2