distortos  v0.5.0
object-oriented C++ RTOS for microcontrollers
Stack.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_STACK_HPP_
13 #define INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_STACK_HPP_
14 
16 
17 #include <memory>
18 
19 #if defined(CONFIG_ARCHITECTURE_ASCENDING_STACK) || defined(CONFIG_ARCHITECTURE_EMPTY_STACK)
20 #error "Support for \"empty ascending\", \"empty descending\" or \"full ascending\" stack not implemented!"
21 #endif // defined(CONFIG_ARCHITECTURE_ASCENDING_STACK) || defined(CONFIG_ARCHITECTURE_EMPTY_STACK)
22 
23 namespace distortos
24 {
25 
26 class Thread;
27 
28 namespace internal
29 {
30 
32 class Stack
33 {
34 public:
35 
37  using StorageUniquePointer = std::unique_ptr<void, void(&)(void*)>;
38 
49  Stack(StorageUniquePointer&& storageUniquePointer, size_t size);
50 
63  Stack(void* storage, size_t size);
64 
69  ~Stack();
70 
75  bool checkStackGuard() const;
76 
87  bool checkStackPointer(const void* const stackPointer) const
88  {
89  return stackPointer >= static_cast<uint8_t*>(adjustedStorage_) + stackGuardSize &&
90  stackPointer <= static_cast<uint8_t*>(adjustedStorage_) + adjustedSize_;
91  }
92 
97  size_t getHighWaterMark() const;
98 
103  size_t getSize() const
104  {
106  }
107 
114  void* getStackPointer() const
115  {
116  return stackPointer_;
117  }
118 
131  int initialize(Thread& thread, void (& run)(Thread&), void (* preTerminationHook)(Thread&),
132  void (& terminationHook)(Thread&));
133 
140  void setStackPointer(void* const stackPointer)
141  {
142  stackPointer_ = stackPointer;
143  }
144 
145  Stack(const Stack&) = delete;
146  Stack(Stack&&) = default;
147  const Stack& operator=(const Stack&) = delete;
148  Stack& operator=(Stack&&) = delete;
149 
150 private:
151 
154 
156  void* const adjustedStorage_;
157 
159  const size_t adjustedSize_;
160 
163 };
164 
165 } // namespace internal
166 
167 } // namespace distortos
168 
169 #endif // INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_STACK_HPP_
int initialize(Thread &thread, void(&run)(Thread &), void(*preTerminationHook)(Thread &), void(&terminationHook)(Thread &))
Fills the stack with stack sentinel, initializes its contents and stack pointer value.
Definition: Stack.cpp:131
size_t getSize() const
Definition: Stack.hpp:103
Stack(StorageUniquePointer &&storageUniquePointer, size_t size)
Stack&#39;s constructor.
Definition: Stack.cpp:85
const size_t adjustedSize_
adjusted size of stack&#39;s storage
Definition: Stack.hpp:159
bool checkStackPointer(const void *const stackPointer) const
Checks whether stack pointer value is within range of this stack.
Definition: Stack.hpp:87
std::unique_ptr< void, void(&)(void *)> StorageUniquePointer
unique_ptr (with deleter) to storage
Definition: Stack.hpp:37
bool checkStackGuard() const
Definition: Stack.cpp:108
~Stack()
Stack&#39;s destructor.
Definition: Stack.cpp:103
void *const adjustedStorage_
adjusted address of stack&#39;s storage
Definition: Stack.hpp:156
Top-level namespace of distortos project.
void thread(uint32_t value, bool &sharedResult)
Test thread.
Definition: ARMv7-M-FpuThreadTestCase.cpp:68
stackGuardSize constant
Stack class is an abstraction of architecture&#39;s stack.
Definition: Stack.hpp:32
StorageUniquePointer storageUniquePointer_
storage for stack
Definition: Stack.hpp:153
constexpr size_t stackGuardSize
size of "stack guard", bytes
Definition: stackGuardSize.hpp:26
void setStackPointer(void *const stackPointer)
Sets value of stack pointer.
Definition: Stack.hpp:140
size_t getHighWaterMark() const
Definition: Stack.cpp:118
void * stackPointer_
current value of stack pointer register
Definition: Stack.hpp:162
Thread class is a pure abstract interface for threads.
Definition: Thread.hpp:32
void * getStackPointer() const
Gets current value of stack pointer.
Definition: Stack.hpp:114