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.

36 lines
950 B

2 years ago
  1. #include "os_default_schduler.hpp"
  2. using namespace std;
  3. using namespace iflytop;
  4. OSDefaultSchduler* OSDefaultSchduler::getInstance() {
  5. static OSDefaultSchduler instance;
  6. return &instance;
  7. }
  8. void OSDefaultSchduler::regPeriodJob(function<void(Context& context)> job, uint32_t period_ms) {
  9. PeriodJob* periodJob = new PeriodJob(job, period_ms);
  10. ZASSERT(periodJob != NULL);
  11. m_periodJobs.push_back(periodJob);
  12. }
  13. void OSDefaultSchduler::loop() {
  14. static uint32_t ticket = 0;
  15. Context context;
  16. if (zos_haspassedms(ticket) < 1) {
  17. return;
  18. }
  19. ticket = zos_get_tick();
  20. for (auto iter = m_periodJobs.begin(); iter != m_periodJobs.end(); iter++) {
  21. auto periodJob = *iter;
  22. if ((uint32_t)zos_haspassedms2(periodJob->lastcall, ticket) < periodJob->period_ms) {
  23. continue;
  24. }
  25. context.periodJob = periodJob;
  26. periodJob->lastcall = ticket;
  27. periodJob->job(context);
  28. periodJob->schedule_times++;
  29. }
  30. }