tutrcos
読み取り中…
検索中…
一致する文字列を見つけられません
semaphore.hpp
[詳解]
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <type_traits>
6
7#include "cmsis_os2.h"
8
9namespace tutrcos {
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) {
23 semaphore_id_ = SemaphoreId{osSemaphoreNew(max, initial, nullptr)};
24 }
25
26 bool try_acquire(uint32_t timeout) {
27 return osSemaphoreAcquire(semaphore_id_.get(), timeout) == osOK;
28 }
29
30 void acquire() { try_acquire(osWaitForever); }
31
32 void release() { osSemaphoreRelease(semaphore_id_.get()); }
33
34private:
35 SemaphoreId semaphore_id_;
36};
37
38} // namespace core
39} // namespace tutrcos
Definition semaphore.hpp:12
bool try_acquire(uint32_t timeout)
Definition semaphore.hpp:26
Semaphore(uint32_t max, uint32_t initial)
Definition semaphore.hpp:22
void release()
Definition semaphore.hpp:32
void acquire()
Definition semaphore.hpp:30
Definition kernel.hpp:7