You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
1.0 KiB

#include "zos_schduler.hpp"
#include "zoslogger.hpp"
#include "ticket.hpp"
using namespace std;
using namespace iflytop;
void ZOSSchduler::regPeriodJob(function<void(Context& context)> job, uint32_t period_ms) {
PeriodJob* periodJob = new PeriodJob(job, period_ms);
ZASSERT(periodJob != NULL);
m_periodJobs.push_back(periodJob);
}
void ZOSSchduler::loop() {
Context context;
if (zos_haspassedms(ticket) < 1) {
return;
}
ticket = zos_get_tick();
for (auto iter = m_periodJobs.begin(); iter != m_periodJobs.end(); iter++) {
auto periodJob = *iter;
if ((uint32_t)zos_haspassedms2(periodJob->lastcall, ticket) < periodJob->period_ms) {
continue;
}
context.periodJob = periodJob;
periodJob->lastcall = ticket;
periodJob->job(context);
periodJob->schedule_times++;
}
}
void ZOSSchduler::startSchedule(const char* threadname, int stack_size, osPriority priority) {
m_thread.init(threadname, stack_size, priority);
m_thread.run([this]() {
while (true) {
loop();
osDelay(1);
}
});
}