ST_engine  0.3-ALPHA
task.hpp
1 /* This file is part of the "ST" project.
2  * You may use, distribute or modify this code under the terms
3  * of the GNU General Public License version 2.
4  * See LICENCE.txt in the root directory of the project.
5  *
6  * Author: Maxim Atanasov
7  * E-mail: maxim.atanasov@protonmail.com
8  */
9 
10 #ifndef TASK_DEF
11 #define TASK_DEF
12 
13 #include "semaphore.hpp"
14 #include <ST_util/linear_frame_allocator_256.hpp>
15 
16 namespace ST {
17 
19 
24  class task {
25  private:
26  static linear_frame_allocator_256<task> allocator;
27 
28  public:
29 
30  void (*task_func)(void *){};
31 
32  void *data{};
33  semaphore *lock = nullptr;
34  semaphore *dependency{};
35 
36  task() = default;
37 
43  task(void (*function)(void *), void *arg, semaphore *dependency) {
44  this->task_func = function;
45  this->data = arg;
46  this->dependency = dependency;
47  }
48 
49  void *operator new(std::size_t) {
50  return allocator.allocate();
51  }
52 
53  void operator delete(void *) {}
54  };
55 }
56 
57 #endif
An object representing a task to be run by the task manager.
Definition: task.hpp:24
task(void(*function)(void *), void *arg, semaphore *dependency)
Definition: task.hpp:43