distortos  v0.5.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 
17 
19 
21 
24 
26 
27 namespace distortos
28 {
29 
30 class SignalsReceiver;
31 
32 namespace internal
33 {
34 
35 class SignalsReceiverControlBlock;
36 class ThreadList;
37 class ThreadGroupControlBlock;
38 
41 {
42 public:
43 
45  enum class UnblockReason : uint8_t
46  {
50  timeout,
51 
52 #if CONFIG_SIGNALS_ENABLE == 1
53 
55  signal,
56 
57 #endif // CONFIG_SIGNALS_ENABLE == 1
58  };
59 
62  class UnblockFunctor : public estd::TypeErasedFunctor<void(ThreadControlBlock&, UnblockReason)>
63  {
64 
65  };
66 
80  ThreadControlBlock(Stack&& stack, uint8_t priority, SchedulingPolicy schedulingPolicy,
81  ThreadGroupControlBlock* threadGroupControlBlock, SignalsReceiver* signalsReceiver, Thread& owner);
82 
88 
101  int addHook();
102 
113  void blockHook(const UnblockFunctor* const unblockFunctor)
114  {
115  unblockFunctor_ = unblockFunctor;
116  }
117 
123  {
124  return list_;
125  }
126 
132  {
134  }
135 
140  Thread& getOwner() const
141  {
142  return owner_;
143  }
144 
150  {
151  return roundRobinQuantum_;
152  }
153 
159  {
160  return schedulingPolicy_;
161  }
162 
163 #if CONFIG_SIGNALS_ENABLE == 1
164 
171  {
173  }
174 
175 #endif // CONFIG_SIGNALS_ENABLE == 1
176 
182  {
183  return stack_;
184  }
185 
190  const Stack& getStack() const
191  {
192  return stack_;
193  }
194 
200  {
201  return state_;
202  }
203 
210  void setList(ThreadList* const list)
211  {
212  list_ = list;
213  }
214 
226  void setPriority(uint8_t priority, bool alwaysBehind = {});
227 
233  void setPriorityInheritanceMutexControlBlock(const MutexControlBlock* const priorityInheritanceMutexControlBlock)
234  {
235  priorityInheritanceMutexControlBlock_ = priorityInheritanceMutexControlBlock;
236  }
237 
242  void setSchedulingPolicy(SchedulingPolicy schedulingPolicy);
243 
248  void setState(const ThreadState state)
249  {
250  state_ = state;
251  }
252 
262  {
263  _impure_ptr = &reent_;
264  }
265 
276  void unblockHook(UnblockReason unblockReason);
277 
288  void updateBoostedPriority(uint8_t boostedPriority = {});
289 
290  ThreadControlBlock(const ThreadControlBlock&) = delete;
292  const ThreadControlBlock& operator=(const ThreadControlBlock&) = delete;
293  ThreadControlBlock& operator=(ThreadControlBlock&&) = delete;
294 
295 private:
296 
311  void reposition(bool loweringBefore);
312 
315 
318 
321 
324 
327 
330 
333 
334 #if CONFIG_SIGNALS_ENABLE == 1
335 
338 
339 #endif // CONFIG_SIGNALS_ENABLE == 1
340 
342  _reent reent_;
343 
346 
349 
352 };
353 
354 } // namespace internal
355 
356 } // namespace distortos
357 
358 #endif // INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCK_HPP_
SignalsReceiverControlBlock * getSignalsReceiverControlBlock() const
Definition: ThreadControlBlock.hpp:170
RoundRobinQuantum class is a quantum of time for round-robin scheduling.
Definition: RoundRobinQuantum.hpp:24
ThreadState getState() const
Definition: ThreadControlBlock.hpp:199
Stack & getStack()
Definition: ThreadControlBlock.hpp:181
Thread & getOwner() const
Definition: ThreadControlBlock.hpp:140
void updateBoostedPriority(uint8_t boostedPriority={})
Updates boosted priority of the thread.
Definition: ThreadControlBlock.cpp:142
void setList(ThreadList *const list)
Sets the list that has this object.
Definition: ThreadControlBlock.hpp:210
RoundRobinQuantum & getRoundRobinQuantum()
Definition: ThreadControlBlock.hpp:149
ThreadControlBlock class is a simple description of a Thread.
Definition: ThreadControlBlock.hpp:40
Definition: TypeErasedFunctor.hpp:19
ThreadGroupControlBlock class is a control block for ThreadGroup.
Definition: ThreadGroupControlBlock.hpp:26
SignalsReceiver class is a container for internal::SignalsReceiverControlBlock.
Definition: SignalsReceiver.hpp:32
MutexControlBlock class is a control block for Mutex.
Definition: MutexControlBlock.hpp:28
ThreadListNode class header.
_reent reent_
newlib&#39;s _reent structure with thread-specific data
Definition: ThreadControlBlock.hpp:342
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
explicit request to unblock the thread - normal unblock
Definition: ThreadControlBlock.hpp:62
RoundRobinQuantum class header.
void blockHook(const UnblockFunctor *const unblockFunctor)
Block hook function of thread.
Definition: ThreadControlBlock.hpp:113
void setState(const ThreadState state)
Definition: ThreadControlBlock.hpp:248
~ThreadControlBlock()
ThreadControlBlock&#39;s destructor.
Definition: ThreadControlBlock.cpp:82
UnblockReason
reason of thread unblocking
Definition: ThreadControlBlock.hpp:45
TypeErasedFunctor template class header.
Stack class header.
void setPriorityInheritanceMutexControlBlock(const MutexControlBlock *const priorityInheritanceMutexControlBlock)
Definition: ThreadControlBlock.hpp:233
Thread & owner_
reference to Thread object that owns this ThreadControlBlock
Definition: ThreadControlBlock.hpp:317
Top-level namespace of distortos project.
ThreadControlBlock(Stack &&stack, uint8_t priority, SchedulingPolicy schedulingPolicy, ThreadGroupControlBlock *threadGroupControlBlock, SignalsReceiver *signalsReceiver, Thread &owner)
ThreadControlBlock constructor.
Definition: ThreadControlBlock.cpp:38
sorted intrusive list of threads (thread control blocks)
Definition: ThreadList.hpp:55
void reposition(bool loweringBefore)
Repositions the thread on the list it&#39;s currently on.
Definition: ThreadControlBlock.cpp:177
SignalsReceiverControlBlock * signalsReceiverControlBlock_
pointer to SignalsReceiverControlBlock object for this thread, nullptr if this thread cannot receive ...
Definition: ThreadControlBlock.hpp:337
Stack class is an abstraction of architecture&#39;s stack.
Definition: Stack.hpp:32
SchedulingPolicy schedulingPolicy_
scheduling policy of the thread
Definition: ThreadControlBlock.hpp:348
const MutexControlBlock * priorityInheritanceMutexControlBlock_
pointer to MutexControlBlock (with PriorityInheritance protocol) that blocks this thread ...
Definition: ThreadControlBlock.hpp:323
int addHook()
Hook function executed when thread is added to scheduler.
Definition: ThreadControlBlock.cpp:89
SchedulingPolicy getSchedulingPolicy() const
Definition: ThreadControlBlock.hpp:158
Stack stack_
internal stack object
Definition: ThreadControlBlock.hpp:314
MutexList ownedProtocolMutexList_
list of mutexes (mutex control blocks) with enabled priority protocol owned by this thread ...
Definition: ThreadControlBlock.hpp:320
RoundRobinQuantum roundRobinQuantum_
round-robin quantum
Definition: ThreadControlBlock.hpp:345
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:351
const UnblockFunctor * unblockFunctor_
functor executed in unblockHook()
Definition: ThreadControlBlock.hpp:332
void setPriority(uint8_t priority, bool alwaysBehind={})
Changes priority of thread.
Definition: ThreadControlBlock.cpp:103
MutexList class header.
MutexList & getOwnedProtocolMutexList()
Definition: ThreadControlBlock.hpp:131
Thread class is a pure abstract interface for threads.
Definition: Thread.hpp:32
const Stack & getStack() const
Definition: ThreadControlBlock.hpp:190
ThreadState
state of the thread
Definition: ThreadState.hpp:28
ThreadList * getList() const
Definition: ThreadControlBlock.hpp:122
signal handler - unblock to deliver unmasked signal
ThreadGroupControlBlock * threadGroupControlBlock_
pointer to ThreadGroupControlBlock with which this object is associated
Definition: ThreadControlBlock.hpp:329
ThreadList * list_
pointer to list that has this object
Definition: ThreadControlBlock.hpp:326
void unblockHook(UnblockReason unblockReason)
Unblock hook function of thread.
Definition: ThreadControlBlock.cpp:133
void setSchedulingPolicy(SchedulingPolicy schedulingPolicy)
Definition: ThreadControlBlock.cpp:125
SchedulingPolicy enum class header.
void switchedToHook()
Hook function called when context is switched to this thread.
Definition: ThreadControlBlock.hpp:261