thread.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_MAX
  30. };
  31. typedef void *(*thread_fn)(void *arg);
  32. typedef struct {
  33. const char *name;
  34. thread_fn fn;
  35. void *arg;
  36. int stksz;
  37. int prio;
  38. }thread_attr_t;
  39. typedef struct {
  40. const char *name;
  41. pthread_t tid;
  42. int quit;
  43. int running;
  44. void *arg;
  45. thread_fn fn;
  46. void *stk;
  47. }thread_handle_t;
  48. int thread_start(int id, thread_fn fn, void *arg);
  49. int thread_start2(int id);
  50. int thread_restart(int id);
  51. int thread_startEx(int id, const char *name, thread_fn fn, void *arg, int stksz, int prio);
  52. int thread_stop(int id);
  53. int thread_stop_all(void);
  54. int thread_is_running(int id);
  55. int thread_start_simp(thread_fn fn, void *arg, int stksz);
  56. int thread_print_stacksize(void);
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif