thread.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 (KB*KB)
  10. enum {
  11. THREAD_ID_WS=0,
  12. THREAD_ID_WEB,
  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_MAX
  20. };
  21. typedef void *(*thread_fn)(void *arg);
  22. typedef struct {
  23. const char *name;
  24. thread_fn fn;
  25. void *arg;
  26. int stksz;
  27. int prio;
  28. }thread_attr_t;
  29. typedef struct {
  30. const char *name;
  31. pthread_t tid;
  32. int quit;
  33. int running;
  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);
  39. int thread_start2(int id);
  40. int thread_restart(int id);
  41. int thread_startEx(int id, const char *name, thread_fn fn, void *arg, int stksz, int prio);
  42. int thread_stop(int id);
  43. int thread_stop_all(void);
  44. int thread_is_running(int id);
  45. int thread_start_simp(thread_fn fn, void *arg, int stksz);
  46. int thread_print_stacksize(void);
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. #endif