distortos  v0.6.0
object-oriented C++ RTOS for microcontrollers
ThreadControlBlock.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCK_HPP_
13 #define INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCK_HPP_
14 
19 
21 
24 
25 namespace distortos
26 {
27 
28 class SignalsReceiver;
29 
30 namespace internal
31 {
32 
33 class RunnableThread;
34 class SignalsReceiverControlBlock;
35 class ThreadList;
36 class ThreadGroupControlBlock;
37 
40 {
41 public:
42 
56  ThreadControlBlock(Stack&& stack, uint8_t priority, SchedulingPolicy schedulingPolicy,
57  ThreadGroupControlBlock* threadGroupControlBlock, SignalsReceiver* signalsReceiver, RunnableThread& owner);
58 
64 
77  int addHook();
78 
89  void blockHook(const UnblockFunctor* const unblockFunctor)
90  {
91  unblockFunctor_ = unblockFunctor;
92  }
93 
99  {
100  return list_;
101  }
102 
108  {
110  }
111 
117  {
118  return owner_;
119  }
120 
126  {
127  return roundRobinQuantum_;
128  }
129 
135  {
136  return schedulingPolicy_;
137  }
138 
143  uintptr_t getSequenceNumber() const
144  {
145  return sequenceNumber_;
146  }
147 
148 #if CONFIG_SIGNALS_ENABLE == 1
149 
156  {
158  }
159 
160 #endif // CONFIG_SIGNALS_ENABLE == 1
161 
167  {
168  return stack_;
169  }
170 
175  const Stack& getStack() const
176  {
177  return stack_;
178  }
179 
185  {
186  return state_;
187  }
188 
195  void setList(ThreadList* const list)
196  {
197  list_ = list;
198  }
199 
211  void setPriority(uint8_t priority, bool alwaysBehind = {});
212 
218  void setPriorityInheritanceMutexControlBlock(const MutexControlBlock* const priorityInheritanceMutexControlBlock)
219  {
220  priorityInheritanceMutexControlBlock_ = priorityInheritanceMutexControlBlock;
221  }
222 
227  void setSchedulingPolicy(SchedulingPolicy schedulingPolicy);
228 
233  void setState(const ThreadState state)
234  {
235  state_ = state;
236  }
237 
247  {
248  _impure_ptr = &reent_;
249  }
250 
261  void unblockHook(UnblockReason unblockReason);
262 
273  void updateBoostedPriority(uint8_t boostedPriority = {});
274 
275  ThreadControlBlock(const ThreadControlBlock&) = delete;
277  const ThreadControlBlock& operator=(const ThreadControlBlock&) = delete;
278  ThreadControlBlock& operator=(ThreadControlBlock&&) = delete;
279 
280 private:
281 
296  void reposition(bool loweringBefore);
297 
300 
302  _reent reent_;
303 
306 
309 
312 
315 
317  uintptr_t sequenceNumber_;
318 
319 #if CONFIG_SIGNALS_ENABLE == 1
320 
323 
324 #endif // CONFIG_SIGNALS_ENABLE == 1
325 
328 
331 
334 
337 
340 };
341 
342 } // namespace internal
343 
344 } // namespace distortos
345 
346 #endif // INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCK_HPP_
ThreadControlBlock(Stack &&stack, uint8_t priority, SchedulingPolicy schedulingPolicy, ThreadGroupControlBlock *threadGroupControlBlock, SignalsReceiver *signalsReceiver, RunnableThread &owner)
ThreadControlBlock's constructor.
Definition: ThreadControlBlock.cpp:51
SignalsReceiverControlBlock * getSignalsReceiverControlBlock() const
Definition: ThreadControlBlock.hpp:155
RoundRobinQuantum class is a quantum of time for round-robin scheduling.
Definition: RoundRobinQuantum.hpp:24
ThreadState getState() const
Definition: ThreadControlBlock.hpp:184
Stack & getStack()
Definition: ThreadControlBlock.hpp:166
RunnableThread & owner_
reference to RunnableThread object that owns this ThreadControlBlock
Definition: ThreadControlBlock.hpp:311
void updateBoostedPriority(uint8_t boostedPriority={})
Updates boosted priority of the thread.
Definition: ThreadControlBlock.cpp:161
void setList(ThreadList *const list)
Sets the list that has this object.
Definition: ThreadControlBlock.hpp:195
RoundRobinQuantum & getRoundRobinQuantum()
Definition: ThreadControlBlock.hpp:125
ThreadControlBlock class is a simple description of a Thread.
Definition: ThreadControlBlock.hpp:39
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
SignalsReceiver class is a container for internal::SignalsReceiverControlBlock.
Definition: SignalsReceiver.hpp:32
MutexControlBlock class is a control block for Mutex.
Definition: MutexControlBlock.hpp:32
ThreadListNode class header.
_reent reent_
newlib's _reent structure with thread-specific data
Definition: ThreadControlBlock.hpp:302
uintptr_t sequenceNumber_
sequence number, one half of thread identifier
Definition: ThreadControlBlock.hpp:317
SchedulingPolicy
scheduling policy of the thread
Definition: SchedulingPolicy.hpp:26
ThreadState enum class header.
SignalsReceiverControlBlock class is a structure required by threads for "receiving" of signals...
Definition: SignalsReceiverControlBlock.hpp:41
RoundRobinQuantum class header.
void blockHook(const UnblockFunctor *const unblockFunctor)
Block hook function of thread.
Definition: ThreadControlBlock.hpp:89
void setState(const ThreadState state)
Definition: ThreadControlBlock.hpp:233
~ThreadControlBlock()
ThreadControlBlock's destructor.
Definition: ThreadControlBlock.cpp:99
Stack class header.
void setPriorityInheritanceMutexControlBlock(const MutexControlBlock *const priorityInheritanceMutexControlBlock)
Definition: ThreadControlBlock.hpp:218
Top-level namespace of distortos project.
sorted intrusive list of threads (thread control blocks)
Definition: ThreadList.hpp:55
void reposition(bool loweringBefore)
Repositions the thread on the list it's currently on.
Definition: ThreadControlBlock.cpp:196
SignalsReceiverControlBlock * signalsReceiverControlBlock_
pointer to SignalsReceiverControlBlock object for this thread, nullptr if this thread cannot receive ...
Definition: ThreadControlBlock.hpp:322
uintptr_t getSequenceNumber() const
Definition: ThreadControlBlock.hpp:143
Stack class is an abstraction of architecture's stack.
Definition: Stack.hpp:32
SchedulingPolicy schedulingPolicy_
scheduling policy of the thread
Definition: ThreadControlBlock.hpp:336
const MutexControlBlock * priorityInheritanceMutexControlBlock_
pointer to MutexControlBlock (with priorityInheritance protocol) that blocks this thread ...
Definition: ThreadControlBlock.hpp:314
int addHook()
Hook function executed when thread is added to scheduler.
Definition: ThreadControlBlock.cpp:108
SchedulingPolicy getSchedulingPolicy() const
Definition: ThreadControlBlock.hpp:134
Stack stack_
internal stack object
Definition: ThreadControlBlock.hpp:305
MutexList ownedProtocolMutexList_
list of mutexes (mutex control blocks) with enabled priority protocol owned by this thread ...
Definition: ThreadControlBlock.hpp:299
RoundRobinQuantum roundRobinQuantum_
round-robin quantum
Definition: ThreadControlBlock.hpp:333
Definition: UnblockFunctor.hpp:29
RunnableThread & getOwner() const
Definition: ThreadControlBlock.hpp:116
ThreadListNode class is a base for ThreadControlBlock that provides nodes for intrusive lists...
Definition: ThreadListNode.hpp:30
ThreadState state_
current state of object
Definition: ThreadControlBlock.hpp:339
const UnblockFunctor * unblockFunctor_
functor executed in unblockHook()
Definition: ThreadControlBlock.hpp:330
void setPriority(uint8_t priority, bool alwaysBehind={})
Changes priority of thread.
Definition: ThreadControlBlock.cpp:122
MutexList class header.
MutexList & getOwnedProtocolMutexList()
Definition: ThreadControlBlock.hpp:107
UnblockReason
reason of thread unblocking
Definition: UnblockReason.hpp:26
UnblockFunctor class header.
const Stack & getStack() const
Definition: ThreadControlBlock.hpp:175
ThreadState
state of the thread
Definition: ThreadState.hpp:28
ThreadList * getList() const
Definition: ThreadControlBlock.hpp:98
ThreadGroupControlBlock * threadGroupControlBlock_
pointer to ThreadGroupControlBlock with which this object is associated
Definition: ThreadControlBlock.hpp:327
ThreadList * list_
pointer to list that has this object
Definition: ThreadControlBlock.hpp:308
void unblockHook(UnblockReason unblockReason)
Unblock hook function of thread.
Definition: ThreadControlBlock.cpp:152
void setSchedulingPolicy(SchedulingPolicy schedulingPolicy)
Definition: ThreadControlBlock.cpp:144
SchedulingPolicy enum class header.
void switchedToHook()
Hook function called when context is switched to this thread.
Definition: ThreadControlBlock.hpp:246