thread.h 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_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_SMTP,
  27. THREAD_ID_TCP,
  28. THREAD_ID_MAX=30
  29. };
  30. typedef void *(*thread_fn)(void *arg);
  31. typedef struct {
  32. pthread_t tid;
  33. int quit;
  34. void *arg;
  35. thread_fn fn;
  36. void *stk;
  37. }thread_handle_t;
  38. int thread_start(int id, thread_fn fn, void *arg, int stksize, int prio);
  39. int thread_stop(int id);
  40. int thread_stop_all(void);
  41. int thread_start_simp(thread_fn fn, void *arg, int stksize);
  42. int thread_print_stacksize(void);
  43. #ifdef __cplusplus
  44. }
  45. #endif
  46. #endif