/
trilirium
/
Pacman
Обзор
Документация
Войти
/
trilirium
/
Pacman
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Scheduler.cpp
109 строк
2 KB
Trilirium
first commit
19 июн 2026, 11:07
19 июн 2026, 11:07
d44591e
Код
Авторство
О чём код?
// Scheduler.cpp // ///////////////////////////////////////////////////////////////////////////// #include "Scheduler.h" using namespace Puckman; ///////////////////////////////////////////////////////////////////////////// // initialization and cleanup ///////////////////////////////////////////////////////////////////////////// Scheduler::Scheduler() { // inits internal timers for (int i = 0; i < 4; i++){ internalTimer[i] = 0; } } Scheduler::~Scheduler() { TasksList::iterator i; // deletes pending tasks for (i = tasksList.begin(); i != tasksList.end(); i++){ delete (*i); } } ///////////////////////////////////////////////////////////////////////////// // internal timers and scheduling ///////////////////////////////////////////////////////////////////////////// // updates the timers void Scheduler::updateInternalTimers() { static int timerLimits[4][2] = { { 0x06, 0xa0 }, // hundredths { 0x0a, 0x60 }, // seconds { 0x0a, 0x60 }, // minutes { 0x0a, 0xa0 } // hours }; // initially only one timer change timerChangesLastFrame = 1; int i = 0; do { // increment counter internalTimer[i]++; // if the LSB of the counter has reached the limit if ((internalTimer[i] & 0x0f) == timerLimits[i][0]){ // increment timer changes timerChangesLastFrame++; // update counter internalTimer[i] = (internalTimer[i] + 0x10) & 0xf0; // if the counter has reached the limit if (internalTimer[i] == timerLimits[i][1]){ // increment timer changes timerChangesLastFrame++; // reset counter internalTimer[i] = 0x00; // goes to the next counter i++; } else break; } else break; } while (i < 4); } // executes scheduled tasks void Scheduler::executeScheduledTasks() { // for all scheduled tasks TasksList::iterator i = tasksList.begin(); while (i != tasksList.end()){ Task *task = (*i); // if a timeUnit has expired if (timerChangesLastFrame > task->timeUnits){ // decrement task remaining units and execute if applicable task->remainingUnits--; if (task->remainingUnits == 0){ task->execute(); i = tasksList.erase(i); delete task; } else { i++; } } else { i++; } } } // adds a task to the task list void Scheduler::addScheduledTask(Task *t) { tasksList.push_back(t); }