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.

66 lines
2.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include <stdio.h>
  3. #include <functional>
  4. #include <list>
  5. // #include "sdk/os/zos.hpp"
  6. #include "osbasic_h.hpp"
  7. #include "zos_thread.hpp"
  8. //
  9. namespace iflytop {
  10. using namespace std;
  11. class ZOSSchduler {
  12. public:
  13. class PeriodJob;
  14. /*******************************************************************************
  15. * Context *
  16. *******************************************************************************/
  17. class Context {
  18. friend class ZOSSchduler;
  19. protected:
  20. PeriodJob* periodJob;
  21. public:
  22. uint32_t getScheduleTimes() { return periodJob->schedule_times; }
  23. };
  24. /*******************************************************************************
  25. * PeriodJob *
  26. *******************************************************************************/
  27. class PeriodJob {
  28. public:
  29. PeriodJob(function<void(Context& context)> job, uint32_t period_ms) {
  30. this->job = job;
  31. this->period_ms = period_ms;
  32. }
  33. function<void(Context& context)> job;
  34. uint32_t period_ms = 0;
  35. uint32_t lastcall = 0;
  36. uint32_t schedule_times = 0;
  37. };
  38. /*******************************************************************************
  39. * PARA *
  40. *******************************************************************************/
  41. list<PeriodJob*> m_periodJobs;
  42. ZOSThread m_thread;
  43. uint32_t ticket = 0;
  44. public:
  45. ZOSSchduler() {}
  46. void initialize(){};
  47. void regPeriodJob(function<void(Context& context)> job, uint32_t period_ms);
  48. void startSchedule(const char* threadname, int stack_size, osPriority priority);
  49. private:
  50. void loop();
  51. };
  52. // #define ZHAL_CORE_REG(period_ms, job) ZOSSchduler::getInstance()->regPeriodJob([this](ZOSSchduler::Context& context) { job }, period_ms);
  53. } // namespace iflytop