distortos  v0.5.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 
57 #if CONFIG_SIGNALS_ENABLE == 1
58 
76  int generateSignal(uint8_t signalNumber) override;
77 
78 #endif // CONFIG_SIGNALS_ENABLE == 1
79 
84  uint8_t getEffectivePriority() const override;
85 
86 #if CONFIG_SIGNALS_ENABLE == 1
87 
100  SignalSet getPendingSignalSet() const override;
101 
102 #endif // CONFIG_SIGNALS_ENABLE == 1
103 
108  uint8_t getPriority() const override;
109 
114  SchedulingPolicy getSchedulingPolicy() const override;
115 
120  size_t getStackHighWaterMark() const override;
121 
126  size_t getStackSize() const override;
127 
132  ThreadState getState() const override;
133 
152  int join() override;
153 
154 #if CONFIG_SIGNALS_ENABLE == 1
155 
174  int queueSignal(uint8_t signalNumber, sigval value) override;
175 
176 #endif // CONFIG_SIGNALS_ENABLE == 1
177 
189  void setPriority(uint8_t priority, bool alwaysBehind = {}) override;
190 
195  void setSchedulingPolicy(SchedulingPolicy schedulingPolicy) override;
196 
197  ThreadCommon(const ThreadCommon&) = delete;
198  ThreadCommon(ThreadCommon&&) = default;
199  const ThreadCommon& operator=(const ThreadCommon&) = delete;
200  ThreadCommon& operator=(ThreadCommon&&) = delete;
201 
202 protected:
203 
209  {
210  return threadControlBlock_;
211  }
212 
218  {
219  return threadControlBlock_;
220  }
221 
235  int startInternal(void (& runFunction)(Thread&), void (* preTerminationHookFunction)(Thread&),
236  void (& terminationHookFunction)(Thread&));
237 
244  static void terminationHook(Thread& thread);
245 
246 private:
247 
250 
253 };
254 
255 } // namespace distortos
256 
257 #endif // INCLUDE_DISTORTOS_THREADCOMMON_HPP_
internal::ThreadControlBlock threadControlBlock_
internal ThreadControlBlock object
Definition: ThreadCommon.hpp:249
const internal::ThreadControlBlock & getThreadControlBlock() const
Definition: ThreadCommon.hpp:217
int generateSignal(uint8_t signalNumber) override
Generates signal for thread.
Definition: ThreadCommon.cpp:48
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:118
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:208
SignalsReceiver class is a container for internal::SignalsReceiverControlBlock.
Definition: SignalsReceiver.hpp:32
SchedulingPolicy getSchedulingPolicy() const override
Definition: ThreadCommon.cpp:84
Semaphore joinSemaphore_
semaphore used by join()
Definition: ThreadCommon.hpp:252
void setPriority(uint8_t priority, bool alwaysBehind={}) override
Changes priority of thread.
Definition: ThreadCommon.cpp:130
SchedulingPolicy
scheduling policy of the thread
Definition: SchedulingPolicy.hpp:26
static void terminationHook(Thread &thread)
Termination hook function of thread.
Definition: ThreadCommon.cpp:155
size_t getStackSize() const override
Definition: ThreadCommon.cpp:94
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:99
uint8_t getEffectivePriority() const override
Definition: ThreadCommon.cpp:60
void setSchedulingPolicy(SchedulingPolicy schedulingPolicy) override
Definition: ThreadCommon.cpp:135
SignalSet class is used as a set of signals.
Definition: SignalSet.hpp:28
uint8_t getPriority() const override
Definition: ThreadCommon.cpp:79
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:67
size_t getStackHighWaterMark() const override
Definition: ThreadCommon.cpp:89
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:144
int join() override
Waits for thread termination.
Definition: ThreadCommon.cpp:104
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:28