thread.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_MAX
  22. };
  23. typedef void (*thread_fn_t)(void *arg);
  24. typedef struct {
  25. const char *name;
  26. thread_fn_t fn;
  27. void *arg;
  28. int stksz;
  29. int prio;
  30. }thread_attr_t;
  31. typedef struct {
  32. pthread_t tid;
  33. int quit;
  34. int running;
  35. thread_attr_t *attr;
  36. }thread_handle_t;
  37. int thread_start(int id, thread_fn_t fn, void *arg);
  38. int thread_start2(int id);
  39. int thread_restart(int id);
  40. int thread_startEx(int id, thread_attr_t *attr);
  41. int thread_stop(int id);
  42. int thread_stop_all(void);
  43. int thread_is_running(int id);
  44. int thread_start_simp(thread_fn_t fn, void *arg, int stksz);
  45. int thread_print_stacksize(void);
  46. #ifdef __cplusplus
  47. }
  48. #endif
  49. #endif