thread.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_RECV_MESSAGE_QUEUE,//进程间通信队列处理线程
  32. THREAD_ID_MAX
  33. };
  34. typedef void *(*thread_fn)(void *arg);
  35. typedef struct {
  36. const char *name;
  37. thread_fn fn;
  38. void *arg;
  39. int stksz;
  40. int prio;
  41. }thread_attr_t;
  42. typedef struct {
  43. const char *name;
  44. pthread_t tid;
  45. int quit;
  46. int running;
  47. void *arg;
  48. thread_fn fn;
  49. void *stk;
  50. }thread_handle_t;
  51. int thread_start(int id, thread_fn fn, void *arg);
  52. int thread_start2(int id);
  53. int thread_restart(int id);
  54. int thread_startEx(int id, const char *name, thread_fn fn, void *arg, int stksz, int prio);
  55. int thread_stop(int id);
  56. int thread_stop_all(void);
  57. int thread_is_running(int id);
  58. int thread_start_simp(thread_fn fn, void *arg, int stksz);
  59. int thread_print_stacksize(void);
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif