thread.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef __THREAD_Hx__
  2. #define __THREAD_Hx__
  3. #include <pthread.h>
  4. #include <stdio.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #define KB 1024
  9. #define MB (1024*1024)
  10. enum {
  11. THREAD_ID_IO=0,
  12. THREAD_ID_WS,
  13. THREAD_ID_WEB,
  14. THREAD_ID_NTP,
  15. THREAD_ID_SNMP,
  16. THREAD_ID_POWER,
  17. THREAD_ID_SENSOR,
  18. THREAD_ID_POLLING,
  19. THREAD_ID_CASCADE,
  20. THREAD_ID_CASCADE_SCAN,
  21. THREAD_ID_SHMW,
  22. THREAD_ID_BREAKER,
  23. THREAD_ID_SWITCH,
  24. THREAD_ID_BREAKER_SCANNER,
  25. THREAD_ID_MQTT,
  26. THREAD_ID_MAIL,
  27. THREAD_ID_TCP,
  28. THREAD_ID_BOARD, //board upgrade
  29. THREAD_ID_UI,
  30. THREAD_ID_Cellular,
  31. THREAD_ID_MAX
  32. };
  33. typedef void *(*thread_fn)(void *arg);
  34. typedef struct {
  35. const char *name;
  36. thread_fn fn;
  37. void *arg;
  38. int stksz;
  39. int prio;
  40. }thread_attr_t;
  41. typedef struct {
  42. const char *name;
  43. pthread_t tid;
  44. int quit;
  45. int running;
  46. void *arg;
  47. thread_fn fn;
  48. void *stk;
  49. }thread_handle_t;
  50. int thread_start(int id, thread_fn fn, void *arg);
  51. int thread_start2(int id);
  52. int thread_restart(int id);
  53. int thread_startEx(int id, const char *name, thread_fn fn, void *arg, int stksz, int prio);
  54. int thread_stop(int id);
  55. int thread_stop_all(void);
  56. int thread_is_running(int id);
  57. int thread_start_simp(thread_fn fn, void *arg, int stksz);
  58. int thread_print_stacksize(void);
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif