AIStatefulTask ‐ Asynchronous, Stateful Task Scheduler library.

Threads-like task objects evolving through user-defined states.

DefaultMemoryPagePool.h
Go to the documentation of this file.
1
28#pragma once
29
30#include "utils/MemoryPagePool.h"
31#include "AIStatefulTaskMutex.h"
32
33namespace statefultask {
34
36class DefaultMemoryPagePoolBase
37{
38 protected:
39 static utils::MemoryPagePool* s_instance;
40
41 protected:
42 static void init(utils::MemoryPagePool* mpp)
43 {
44 // Only create one DefaultMemoryPagePool object (at the top of main()).
45 ASSERT(s_instance == nullptr);
46 s_instance = mpp;
48 }
49
50 DefaultMemoryPagePoolBase() = default;
51 ~DefaultMemoryPagePoolBase()
52 {
53 delete s_instance;
54 s_instance = nullptr;
55 }
56};
58
114template<typename MPP = utils::MemoryPagePool>
115class DefaultMemoryPagePool : private DefaultMemoryPagePoolBase
116{
117 public:
119 DefaultMemoryPagePool(size_t block_size = 0x8000, utils::MemoryPagePool::blocks_t minimum_chunk_size = 0, utils::MemoryPagePool::blocks_t maximum_chunk_size = 0)
120 {
121 init(new MPP(block_size, minimum_chunk_size, maximum_chunk_size));
122 }
123
130 template<typename... ArgT>
131 DefaultMemoryPagePool(ArgT&&... args)
132 {
133 init(new MPP(std::forward<ArgT>(args)...));
134 }
135
142 static utils::MemoryPagePool& instance()
143 {
144 // Create a statefultask::DefaultMemoryPagePool at the top of main,
145 // and/or don't use anything from statefultask in constructors/destructors
146 // of global and/or static objects.
147 ASSERT(s_instance);
148 return *s_instance;
149 }
150};
151
152} // namespace statefultask
153
Mutex for stateful tasks. Declaration of class AIStatefulTaskMutex.
static void init(utils::MemoryPagePool *mpp_ptr)
This must be called once before using a AIStatefulTaskMutex.
Definition: AIStatefulTaskMutex.h:208
Definition: DefaultMemoryPagePool.h:116
DefaultMemoryPagePool(ArgT &&... args)
Definition: DefaultMemoryPagePool.h:131
static utils::MemoryPagePool & instance()
Definition: DefaultMemoryPagePool.h:142
DefaultMemoryPagePool(size_t block_size=0x8000, utils::MemoryPagePool::blocks_t minimum_chunk_size=0, utils::MemoryPagePool::blocks_t maximum_chunk_size=0)
Constructor with the same (default) arguments as <span class="inlinecode">utils::MemoryPagePool</spa...
Definition: DefaultMemoryPagePool.h:119
Tasks defined by the library project are put into this namespace.
Definition: AIStatefulTask.h:857