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.

48 lines
975 B

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include "osbasic_h.hpp"
  3. namespace iflytop {
  4. typedef function<void()> zosthread_cb_t;
  5. class ZThread {
  6. public:
  7. typedef enum {
  8. kidle,
  9. kworking,
  10. kdead,
  11. } status_t;
  12. const char* m_name;
  13. size_t m_stacksize;
  14. osPriority m_uxPriority;
  15. status_t m_status = kidle;
  16. #if 0
  17. bool m_threadisworkingFlag = false;
  18. bool m_threadisWaitingForStopFlag = false;
  19. #endif
  20. bool m_threadisworkingFlagCallSide = false;
  21. zosthread_cb_t m_taskfunction;
  22. EventGroupHandle_t m_zthreadstartworkevent;
  23. osThreadId m_defaultTaskHandle;
  24. SemaphoreHandle_t m_lock;
  25. public:
  26. void init(const char* threadname, int stack_size = 1024, osPriority priority = osPriorityNormal);
  27. void start(zosthread_cb_t cb);
  28. void stop();
  29. bool getExitFlag() { return !m_threadisworkingFlagCallSide; }
  30. bool isworking() { return m_status == kworking; }
  31. void sleep(uint32_t ms);
  32. void wake();
  33. public:
  34. void threadcb();
  35. };
  36. } // namespace iflytop