stm32rcos
 
読み取り中…
検索中…
一致する文字列を見つけられません
thread.hpp
[詳解]
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <memory>
6#include <type_traits>
7
8#include <cmsis_os2.h>
9
10namespace stm32rcos {
11namespace core {
12
13class Thread {
14private:
15 struct Deleter {
16 void operator()(osThreadId_t thread_id) { osThreadTerminate(thread_id); }
17 };
18
19 using ThreadId =
20 std::unique_ptr<std::remove_pointer_t<osThreadId_t>, Deleter>;
21
22public:
23 Thread(void (*func)(void *), void *args, size_t stack_size,
24 osPriority_t priority, uint32_t attr_bits = 0) {
25 osThreadAttr_t attr{};
26 attr.stack_size = stack_size;
27 attr.priority = priority;
28 attr.attr_bits = attr_bits;
29 thread_id_ = ThreadId{osThreadNew(func, args, &attr)};
30 }
31
32 bool detach() { return osThreadDetach(thread_id_.get()) == osOK; }
33
34 bool join() { return osThreadJoin(thread_id_.get()) == osOK; }
35
36private:
37 ThreadId thread_id_;
38};
39
40} // namespace core
41} // namespace stm32rcos
bool join()
Definition thread.hpp:34
bool detach()
Definition thread.hpp:32
Thread(void(*func)(void *), void *args, size_t stack_size, osPriority_t priority, uint32_t attr_bits=0)
Definition thread.hpp:23
Definition mutex.hpp:10
Definition mutex.hpp:9