thread.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef __THREAD_Hx__
  2. #define __THREAD_Hx__
  3. #include <pthread.h>
  4. #include <stdio.h>
  5. #include "log.h"
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define KB 1024
  10. #define MB (KB*KB)
  11. enum {
  12. THREAD_ID_WEB=0,
  13. THREAD_ID_SNMP,
  14. THREAD_ID_POWER,
  15. THREAD_ID_POLL,
  16. THREAD_ID_MQTT,
  17. THREAD_ID_MAIL,
  18. THREAD_ID_UI,
  19. THREAD_ID_CAS_SCAN,
  20. THREAD_ID_CAS_TH,
  21. THREAD_ID_SENSOR,
  22. THREAD_ID_CAS_FREE_SCAN,
  23. THREAD_ID_CAS_FREE_ENTRY,
  24. THREAD_ID_CAS_FREE_POLL,
  25. THREAD_ID_CAS_TCP,
  26. THREAD_ID_MAX
  27. };
  28. typedef void (*thread_fn_t)(void *arg);
  29. typedef struct {
  30. const char *name;
  31. thread_fn_t fn;
  32. void *arg;
  33. int stksz;
  34. int prio;
  35. }thread_attr_t;
  36. typedef struct {
  37. pthread_t tid;
  38. int quit;
  39. int running;
  40. thread_attr_t *attr;
  41. }thread_handle_t;
  42. int thread_start(int id, thread_fn_t fn, void *arg);
  43. int thread_start2(int id);
  44. int thread_restart(int id);
  45. int thread_startEx(int id, thread_attr_t *attr);
  46. int thread_stop(int id);
  47. int thread_stop_all(void);
  48. int thread_is_running(int id);
  49. int thread_start_simp(thread_fn_t fn, void *arg, int stksz);
  50. int thread_print_stacksize(void);
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #endif