distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
ThreadCommon.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_THREADCOMMON_HPP_
13 #define INCLUDE_DISTORTOS_THREADCOMMON_HPP_
14 
16 
17 #include "distortos/Semaphore.hpp"
18 #include "distortos/Thread.hpp"
19 
20 namespace distortos
21 {
22 
29 class ThreadCommon : public Thread
30 {
31 public:
32 
35 
48  ThreadCommon(internal::Stack&& stack, uint8_t priority, SchedulingPolicy schedulingPolicy,
49  internal::ThreadGroupControlBlock* threadGroupControlBlock, SignalsReceiver* signalsReceiver);
50 
55  ~ThreadCommon() override;
56 
74  int generateSignal(uint8_t signalNumber) override;
75 
80  uint8_t getEffectivePriority() const override;
81 
94  SignalSet getPendingSignalSet() const override;
95 
100  uint8_t getPriority() const override;
101 
106  SchedulingPolicy getSchedulingPolicy() const override;
107 
112  size_t getStackHighWaterMark() const override;
113 
118  size_t getStackSize() const override;
119 
124  ThreadState getState() const override;
125 
144  int join() override;
145 
164  int queueSignal(uint8_t signalNumber, sigval value) override;
165 
177  void setPriority(uint8_t priority, bool alwaysBehind = {}) override;
178 
183  void setSchedulingPolicy(SchedulingPolicy schedulingPolicy) override;
184 
185  ThreadCommon(const ThreadCommon&) = delete;
186  ThreadCommon(ThreadCommon&&) = default;
187  const ThreadCommon& operator=(const ThreadCommon&) = delete;
188  ThreadCommon& operator=(ThreadCommon&&) = delete;
189 
190 protected:
191 
197  {
198  return threadControlBlock_;
199  }
200 
206  {
207  return threadControlBlock_;
208  }
209 
223  int startInternal(void (& runFunction)(Thread&), void (* preTerminationHookFunction)(Thread&),
224  void (& terminationHookFunction)(Thread&));
225 
232  static void terminationHook(Thread& thread);
233 
234 private:
235 
238 
241 };
242 
243 } // namespace distortos
244 
245 #endif // INCLUDE_DISTORTOS_THREADCOMMON_HPP_
internal::ThreadControlBlock threadControlBlock_
internal ThreadControlBlock object
Definition: ThreadCommon.hpp:237
const internal::ThreadControlBlock & getThreadControlBlock() const
Definition: ThreadCommon.hpp:205
int generateSignal(uint8_t signalNumber) override
Generates signal for thread.
Definition: ThreadCommon.cpp:46
Definition: signal.h:28
Semaphore is the basic synchronization primitive.
Definition: Semaphore.hpp:30
int queueSignal(uint8_t signalNumber, sigval value) override
Queues signal for thread.
Definition: ThreadCommon.cpp:108
ThreadControlBlock class is a simple description of a Thread.
Definition: ThreadControlBlock.hpp:40
ThreadControlBlock class header.
ThreadGroupControlBlock class is a control block for ThreadGroup.
Definition: ThreadGroupControlBlock.hpp:26
internal::ThreadControlBlock & getThreadControlBlock()
Definition: ThreadCommon.hpp:196
SignalsReceiver class is a container for internal::SignalsReceiverControlBlock.
Definition: SignalsReceiver.hpp:28
SchedulingPolicy getSchedulingPolicy() const override
Definition: ThreadCommon.cpp:76
Semaphore joinSemaphore_
semaphore used by join()
Definition: ThreadCommon.hpp:240
void setPriority(uint8_t priority, bool alwaysBehind={}) override
Changes priority of thread.
Definition: ThreadCommon.cpp:118
SchedulingPolicy
scheduling policy of the thread
Definition: SchedulingPolicy.hpp:26
static void terminationHook(Thread &thread)
Termination hook function of thread.
Definition: ThreadCommon.cpp:143
size_t getStackSize() const override
Definition: ThreadCommon.cpp:86
std::unique_ptr< void, void(&)(void *)> StorageUniquePointer
unique_ptr (with deleter) to storage
Definition: Stack.hpp:37
Semaphore class header.
ThreadState getState() const override
Definition: ThreadCommon.cpp:91
uint8_t getEffectivePriority() const override
Definition: ThreadCommon.cpp:56
void setSchedulingPolicy(SchedulingPolicy schedulingPolicy) override
Definition: ThreadCommon.cpp:123
SignalSet class is used as a set of signals.
Definition: SignalSet.hpp:28
uint8_t getPriority() const override
Definition: ThreadCommon.cpp:71
Top-level namespace of distortos project.
ThreadCommon class implements common functionality of threads.
Definition: ThreadCommon.hpp:29
void thread(uint32_t value, bool &sharedResult)
Test thread.
Definition: ARMv7-M-FpuThreadTestCase.cpp:68
SignalSet getPendingSignalSet() const override
Gets set of currently pending signals.
Definition: ThreadCommon.cpp:61
size_t getStackHighWaterMark() const override
Definition: ThreadCommon.cpp:81
internal::Stack::StorageUniquePointer StackStorageUniquePointer
unique_ptr (with deleter) to storage for stack
Definition: ThreadCommon.hpp:34
Stack class is an abstraction of architecture&#39;s stack.
Definition: Stack.hpp:32
~ThreadCommon() override
ThreadCommon&#39;s destructor.
Definition: ThreadCommon.cpp:41
Thread class header.
int startInternal(void(&runFunction)(Thread &), void(*preTerminationHookFunction)(Thread &), void(&terminationHookFunction)(Thread &))
Starts the thread.
Definition: ThreadCommon.cpp:132
int join() override
Waits for thread termination.
Definition: ThreadCommon.cpp:96
ThreadCommon(internal::Stack &&stack, uint8_t priority, SchedulingPolicy schedulingPolicy, internal::ThreadGroupControlBlock *threadGroupControlBlock, SignalsReceiver *signalsReceiver)
ThreadCommon&#39;s constructor.
Definition: ThreadCommon.cpp:32
Thread class is a pure abstract interface for threads.
Definition: Thread.hpp:32
ThreadState
state of the thread
Definition: ThreadState.hpp:26