stm32rcos
 
読み取り中…
検索中…
一致する文字列を見つけられません
semaphore.hpp
[詳解]
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <type_traits>
6
7#include <cmsis_os2.h>
8
9namespace stm32rcos {
10namespace core {
11
12class Semaphore {
13private:
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
21public:
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
36private:
37 SemaphoreId semaphore_id_;
38};
39
40} // namespace core
41} // namespace stm32rcos
bool try_acquire(uint32_t timeout)
Definition semaphore.hpp:28
void acquire()
Definition semaphore.hpp:32
Semaphore(uint32_t max, uint32_t initial, uint32_t attr_bits=0)
Definition semaphore.hpp:22
void release()
Definition semaphore.hpp:34
Definition mutex.hpp:10
Definition mutex.hpp:9