thread.h 1.3 KB

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