/
AlanForster
/
ProcessTableSoft
Обзор
Документация
Войти
/
AlanForster
/
ProcessTableSoft
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
ProcessTable.cpp
65 строк
1 KB
AlanForster
Первый шаг на пути разработки
20 окт 2025, 20:58
20 окт 2025, 20:58
b8de6e4
Код
Авторство
О чём код?
#include "ProcessTable.h" ProcessTable::ProcessTable() { std::clog << "Activating of PTS..." << std::endl; } ProcessTable::~ProcessTable() { std::clog << "Deactivating of PTS..." << std::endl; for (auto& p : this->pool) { auto process = std::move(std::get<1>(p)); if (process.joinable()) { process.join(); } } } void ProcessTable::addProcess(std::thread&& th) { auto id = th.get_id(); time_t time_of_start = time(NULL); auto status = 0; proc_t proc = std::make_tuple(id, th, time_of_start, status); this->pool.push_back(proc); } void ProcessTable::executeProcess() { if (this->pool.empty()) { return; // �������� �� ��������� ���������� } proc_t proc = this->pool.pop_front(); auto th = std::move(std::get<1>(proc)); if (th.joinable()) { th.join(); } } void ProcessTable::executeAllProcesses() { if (this->pool.empty()) { return; // �������� �� ��������� ���������� } while (!this->pool.empty()) { proc_t proc = this->pool.pop_front(); auto th = std::move(std::get<1>(proc)); th.join(); } } std::thread ProcessTable::getProcess(int id) { if (this->pool.empty()) { return; // �������� �� ��������� ���������� } proc_t proc = this->pool.pop_front(); auto th = std::move(std::get<1>(proc)); return th; } void ProcessTable::updateTable() { for (auto& p : this->pool) { auto th = std::move(std::get<1>(p)); if (!th.joinable()) { p = std::make_tuple(std::get<0>(p), th, std::get<2>(p), 1); } } }