TaskManagerIO
Loading...
Searching...
No Matches
TaskBlock.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry)..
3 * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4 */
5
6#ifndef _TASKMANAGERIO_TASKBLOCK_H_
7#define _TASKMANAGERIO_TASKBLOCK_H_
8
9#include "TaskPlatformDeps.h"
10#include "TaskTypes.h"
11
16
26class TaskBlock {
27private:
28 TimerTask tasks[DEFAULT_TASK_SIZE];
29 const taskid_t first;
30 const taskid_t tasksSize;
31public:
32 explicit TaskBlock(taskid_t first_) : first(first_), tasksSize(DEFAULT_TASK_SIZE) {}
33
39 bool isTaskContained(taskid_t task) const {
40 return task >= first && task < (first + tasksSize);
41 };
42
43 TimerTask* getContainedTask(taskid_t task) {
44 return isTaskContained(task) ? &tasks[task - first] : nullptr;
45 }
46
47 void clearAll() {
48 for(taskid_t i=0; i<tasksSize;i++) {
49 tasks[i].clear();
50 }
51 }
52
53 taskid_t allocateTask() {
54 for(taskid_t i=0; i<tasksSize; i++) {
55 if(tasks[i].allocateIfPossible()) {
56 return i + first;
57 }
58 }
59 return TASKMGR_INVALIDID;
60 }
61
62 taskid_t lastSlot() const {
63 return first + tasksSize - 1;
64 }
65
66 taskid_t firstSlot() const {
67 return first;
68 }
69};
70
71
72#endif //_TASKMANAGERIO_TASKBLOCK_H_
provides the platform specific configuration for task manager
This class represents the core tasks that are added to task manager, and the TimerTask object itself.
unsigned int taskid_t
Definition TaskTypes.h:22
bool isTaskContained(taskid_t task) const
Definition TaskBlock.h:39
Definition TaskTypes.h:163