distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
ThreadCommon.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCOMMON_HPP_
13 #define INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCOMMON_HPP_
14 
17 
18 #include "distortos/Semaphore.hpp"
19 
20 namespace distortos
21 {
22 
23 namespace internal
24 {
25 
28 {
29 public:
30 
33 
46  ThreadCommon(Stack&& stack, uint8_t priority, SchedulingPolicy schedulingPolicy,
47  ThreadGroupControlBlock* threadGroupControlBlock, SignalsReceiver* signalsReceiver);
48 
53  ~ThreadCommon() override;
54 
55 #if DISTORTOS_SIGNALS_ENABLE == 1
56 
74  int generateSignal(uint8_t signalNumber) override;
75 
76 #endif // DISTORTOS_SIGNALS_ENABLE == 1
77 
82  uint8_t getEffectivePriority() const override;
83 
89  ThreadIdentifier getIdentifier() const override;
90 
91 #if DISTORTOS_SIGNALS_ENABLE == 1
92 
105  SignalSet getPendingSignalSet() const override;
106 
107 #endif // DISTORTOS_SIGNALS_ENABLE == 1
108 
113  uint8_t getPriority() const override;
114 
119  SchedulingPolicy getSchedulingPolicy() const override;
120 
125  size_t getStackHighWaterMark() const override;
126 
131  size_t getStackSize() const override;
132 
137  ThreadState getState() const override;
138 
157  int join() override;
158 
159 #if DISTORTOS_SIGNALS_ENABLE == 1
160 
179  int queueSignal(uint8_t signalNumber, sigval value) override;
180 
181 #endif // DISTORTOS_SIGNALS_ENABLE == 1
182 
194  void setPriority(uint8_t priority, bool alwaysBehind = {}) override;
195 
200  void setSchedulingPolicy(SchedulingPolicy schedulingPolicy) override;
201 
202  ThreadCommon(const ThreadCommon&) = delete;
203  ThreadCommon(ThreadCommon&&) = default;
204  const ThreadCommon& operator=(const ThreadCommon&) = delete;
205  ThreadCommon& operator=(ThreadCommon&&) = delete;
206 
207 protected:
208 
217  void exit0Hook() override;
218 
227  void exit1Hook() override;
228 
234  {
235  return threadControlBlock_;
236  }
237 
243  {
244  return threadControlBlock_;
245  }
246 
256  int startInternal();
257 
258 private:
259 
262 
265 };
266 
267 } // namespace internal
268 
269 } // namespace distortos
270 
271 #endif // INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCOMMON_HPP_
~ThreadCommon() override
ThreadCommon's destructor.
Definition: ThreadCommon.cpp:45
int generateSignal(uint8_t signalNumber) override
Generates signal for thread.
Definition: ThreadCommon.cpp:52
Definition: signal.h:28
uint8_t getEffectivePriority() const override
Definition: ThreadCommon.cpp:64
Semaphore is the basic synchronization primitive.
Definition: Semaphore.hpp:30
SchedulingPolicy getSchedulingPolicy() const override
Definition: ThreadCommon.cpp:94
ThreadControlBlock class is a simple description of a Thread.
Definition: ThreadControlBlock.hpp:39
ThreadControlBlock & getThreadControlBlock()
Definition: ThreadCommon.hpp:233
size_t getStackSize() const override
Definition: ThreadCommon.cpp:104
SignalSet getPendingSignalSet() const override
Gets set of currently pending signals.
Definition: ThreadCommon.cpp:77
Semaphore joinSemaphore_
semaphore used by join()
Definition: ThreadCommon.hpp:264
ThreadControlBlock class header.
ThreadGroupControlBlock class is a control block for ThreadGroup.
Definition: ThreadGroupControlBlock.hpp:26
RunnableThread class defines additional interface functions required for the thread to be actually ru...
Definition: RunnableThread.hpp:24
void setPriority(uint8_t priority, bool alwaysBehind={}) override
Changes priority of thread.
Definition: ThreadCommon.cpp:140
SignalsReceiver class is a container for internal::SignalsReceiverControlBlock.
Definition: SignalsReceiver.hpp:32
SchedulingPolicy
scheduling policy of the thread
Definition: SchedulingPolicy.hpp:26
ThreadState getState() const override
Definition: ThreadCommon.cpp:109
std::unique_ptr< void, void(&)(void *)> StorageUniquePointer
unique_ptr (with deleter) to storage
Definition: Stack.hpp:37
Semaphore class header.
int join() override
Waits for thread termination.
Definition: ThreadCommon.cpp:114
ThreadCommon(Stack &&stack, uint8_t priority, SchedulingPolicy schedulingPolicy, ThreadGroupControlBlock *threadGroupControlBlock, SignalsReceiver *signalsReceiver)
ThreadCommon's constructor.
Definition: ThreadCommon.cpp:36
Stack::StorageUniquePointer StackStorageUniquePointer
unique_ptr (with deleter) to storage for stack
Definition: ThreadCommon.hpp:32
ThreadIdentifier getIdentifier() const override
Definition: ThreadCommon.cpp:69
void exit0Hook() override
Thread's "exit 0" hook function.
Definition: ThreadCommon.cpp:154
SignalSet class is used as a set of signals.
Definition: SignalSet.hpp:28
Top-level namespace of distortos project.
Definition: buttons.hpp:33
ThreadControlBlock threadControlBlock_
internal ThreadControlBlock object
Definition: ThreadCommon.hpp:261
Stack class is an abstraction of architecture's stack.
Definition: Stack.hpp:32
size_t getStackHighWaterMark() const override
Definition: ThreadCommon.cpp:99
int startInternal()
Starts the thread.
Definition: ThreadCommon.cpp:164
RunnableThread class header.
const ThreadControlBlock & getThreadControlBlock() const
Definition: ThreadCommon.hpp:242
ThreadIdentifier class is an identifier of thread.
Definition: ThreadIdentifier.hpp:52
void exit1Hook() override
Thread's "exit 1" hook function.
Definition: ThreadCommon.cpp:159
ThreadCommon class implements common functionality of threads.
Definition: ThreadCommon.hpp:27
ThreadState
state of the thread
Definition: ThreadState.hpp:28
int queueSignal(uint8_t signalNumber, sigval value) override
Queues signal for thread.
Definition: ThreadCommon.cpp:128
void setSchedulingPolicy(SchedulingPolicy schedulingPolicy) override
Definition: ThreadCommon.cpp:145
uint8_t getPriority() const override
Definition: ThreadCommon.cpp:89