distortos  v0.4.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,
52  signal,
53  };
54 
57  class UnblockFunctor : public estd::TypeErasedFunctor<void(ThreadControlBlock&, UnblockReason)>
58  {
59 
60  };
61 
75  ThreadControlBlock(Stack&& stack, uint8_t priority, SchedulingPolicy schedulingPolicy,
76  ThreadGroupControlBlock* threadGroupControlBlock, SignalsReceiver* signalsReceiver, Thread& owner);
77 
83 
96  int addHook();
97 
108  void blockHook(const UnblockFunctor* const unblockFunctor)
109  {
110  unblockFunctor_ = unblockFunctor;
111  }
112 
118  {
119  return list_;
120  }
121 
127  {
129  }
130 
135  Thread& getOwner() const
136  {
137  return owner_;
138  }
139 
145  {
146  return roundRobinQuantum_;
147  }
148 
154  {
155  return schedulingPolicy_;
156  }
157 
164  {
166  }
167 
173  {
174  return stack_;
175  }
176 
181  const Stack& getStack() const
182  {
183  return stack_;
184  }
185 
191  {
192  return state_;
193  }
194 
201  void setList(ThreadList* const list)
202  {
203  list_ = list;
204  }
205 
217  void setPriority(uint8_t priority, bool alwaysBehind = {});
218 
224  void setPriorityInheritanceMutexControlBlock(const MutexControlBlock* const priorityInheritanceMutexControlBlock)
225  {
226  priorityInheritanceMutexControlBlock_ = priorityInheritanceMutexControlBlock;
227  }
228 
233  void setSchedulingPolicy(SchedulingPolicy schedulingPolicy);
234 
239  void setState(const ThreadState state)
240  {
241  state_ = state;
242  }
243 
253  {
254  _impure_ptr = &reent_;
255  }
256 
267  void unblockHook(UnblockReason unblockReason);
268 
279  void updateBoostedPriority(uint8_t boostedPriority = {});
280 
281  ThreadControlBlock(const ThreadControlBlock&) = delete;
283  const ThreadControlBlock& operator=(const ThreadControlBlock&) = delete;
284  ThreadControlBlock& operator=(ThreadControlBlock&&) = delete;
285 
286 private:
287 
302  void reposition(bool loweringBefore);
303 
306 
309 
312 
315 
318 
321 
324 
327 
329  _reent reent_;
330 
333 
336 
339 };
340 
341 } // namespace internal
342 
343 } // namespace distortos
344 
345 #endif // INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_THREADCONTROLBLOCK_HPP_
SignalsReceiverControlBlock * getSignalsReceiverControlBlock() const
Definition: ThreadControlBlock.hpp:163
RoundRobinQuantum class is a quantum of time for round-robin scheduling.
Definition: RoundRobinQuantum.hpp:24
ThreadState getState() const
Definition: ThreadControlBlock.hpp:190
Stack & getStack()
Definition: ThreadControlBlock.hpp:172
Thread & getOwner() const
Definition: ThreadControlBlock.hpp:135
void updateBoostedPriority(uint8_t boostedPriority={})
Updates boosted priority of the thread.
Definition: ThreadControlBlock.cpp:118
void setList(ThreadList *const list)
Sets the list that has this object.
Definition: ThreadControlBlock.hpp:201
RoundRobinQuantum & getRoundRobinQuantum()
Definition: ThreadControlBlock.hpp:144
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:28
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:329
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:37
explicit request to unblock the thread - normal unblock
Definition: ThreadControlBlock.hpp:57
RoundRobinQuantum class header.
void blockHook(const UnblockFunctor *const unblockFunctor)
Block hook function of thread.
Definition: ThreadControlBlock.hpp:108
void setState(const ThreadState state)
Definition: ThreadControlBlock.hpp:239
~ThreadControlBlock()
ThreadControlBlock&#39;s destructor.
Definition: ThreadControlBlock.cpp:58
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:224
Thread & owner_
reference to Thread object that owns this ThreadControlBlock
Definition: ThreadControlBlock.hpp:308
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:36
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:153
SignalsReceiverControlBlock * signalsReceiverControlBlock_
pointer to SignalsReceiverControlBlock object for this thread, nullptr if this thread cannot receive ...
Definition: ThreadControlBlock.hpp:326
Stack class is an abstraction of architecture&#39;s stack.
Definition: Stack.hpp:32
SchedulingPolicy schedulingPolicy_
scheduling policy of the thread
Definition: ThreadControlBlock.hpp:335
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:65
SchedulingPolicy getSchedulingPolicy() const
Definition: ThreadControlBlock.hpp:153
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:311
RoundRobinQuantum roundRobinQuantum_
round-robin quantum
Definition: ThreadControlBlock.hpp:332
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:338
const UnblockFunctor * unblockFunctor_
functor executed in unblockHook()
Definition: ThreadControlBlock.hpp:323
void setPriority(uint8_t priority, bool alwaysBehind={})
Changes priority of thread.
Definition: ThreadControlBlock.cpp:79
MutexList class header.
MutexList & getOwnedProtocolMutexList()
Definition: ThreadControlBlock.hpp:126
Thread class is a pure abstract interface for threads.
Definition: Thread.hpp:32
const Stack & getStack() const
Definition: ThreadControlBlock.hpp:181
ThreadState
state of the thread
Definition: ThreadState.hpp:26
ThreadList * getList() const
Definition: ThreadControlBlock.hpp:117
signal handler - unblock to deliver unmasked signal
ThreadGroupControlBlock * threadGroupControlBlock_
pointer to ThreadGroupControlBlock with which this object is associated
Definition: ThreadControlBlock.hpp:320
ThreadList * list_
pointer to list that has this object
Definition: ThreadControlBlock.hpp:317
void unblockHook(UnblockReason unblockReason)
Unblock hook function of thread.
Definition: ThreadControlBlock.cpp:109
void setSchedulingPolicy(SchedulingPolicy schedulingPolicy)
Definition: ThreadControlBlock.cpp:101
SchedulingPolicy enum class header.
void switchedToHook()
Hook function called when context is switched to this thread.
Definition: ThreadControlBlock.hpp:252