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.

67 lines
1.3 KiB

1 year 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. uint32_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. zosthread_cb_t m_taskfunction_exitcb;
  23. EventGroupHandle_t m_zthreadstartworkevent;
  24. osThreadId m_defaultTaskHandle;
  25. SemaphoreHandle_t m_lock;
  26. public:
  27. /**
  28. * @brief init in zos.cpp, called by zos_init
  29. */
  30. static void zthread_module_init();
  31. void init(const char* threadname, int stack_size = 512, osPriority priority = osPriorityNormal);
  32. void start(zosthread_cb_t cb);
  33. void start(zosthread_cb_t cb, zosthread_cb_t exitcb);
  34. void stop();
  35. bool getExitFlag() { return !m_threadisworkingFlagCallSide; }
  36. bool isworking() { return m_status == kworking; }
  37. void wake();
  38. static void sleep(uint32_t ms);
  39. static ZThread* getThread();
  40. public:
  41. void threadcb();
  42. };
  43. class ThisThread {
  44. ZThread* thread;
  45. public:
  46. ThisThread();
  47. bool getExitFlag();
  48. bool isworking();
  49. void sleep(uint32_t ms);
  50. };
  51. } // namespace iflytop