threads.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_THREADS_H
  3. #define NETDATA_THREADS_H 1
  4. #include "../libnetdata.h"
  5. pid_t gettid(void);
  6. typedef enum {
  7. NETDATA_THREAD_OPTION_DEFAULT = 0 << 0,
  8. NETDATA_THREAD_OPTION_JOINABLE = 1 << 0,
  9. NETDATA_THREAD_OPTION_DONT_LOG_STARTUP = 1 << 1,
  10. NETDATA_THREAD_OPTION_DONT_LOG_CLEANUP = 1 << 2,
  11. NETDATA_THREAD_OPTION_DONT_LOG = NETDATA_THREAD_OPTION_DONT_LOG_STARTUP|NETDATA_THREAD_OPTION_DONT_LOG_CLEANUP,
  12. } NETDATA_THREAD_OPTIONS;
  13. #define netdata_thread_cleanup_push(func, arg) pthread_cleanup_push(func, arg)
  14. #define netdata_thread_cleanup_pop(execute) pthread_cleanup_pop(execute)
  15. typedef pthread_t netdata_thread_t;
  16. #define NETDATA_THREAD_TAG_MAX 100
  17. const char *netdata_thread_tag(void);
  18. int netdata_thread_tag_exists(void);
  19. size_t netdata_threads_init(void);
  20. void netdata_threads_init_after_fork(size_t stacksize);
  21. int netdata_thread_create(netdata_thread_t *thread, const char *tag, NETDATA_THREAD_OPTIONS options, void *(*start_routine) (void *), void *arg);
  22. #ifdef NETDATA_INTERNAL_CHECKS
  23. #define netdata_thread_cancel(thread) netdata_thread_cancel_with_trace(thread, __LINE__, __FILE__, __FUNCTION__)
  24. int netdata_thread_cancel_with_trace(netdata_thread_t thread, int line, const char *file, const char *function);
  25. #else
  26. int netdata_thread_cancel(netdata_thread_t thread);
  27. #endif
  28. int netdata_thread_join(netdata_thread_t thread, void **retval);
  29. int netdata_thread_detach(pthread_t thread);
  30. #define NETDATA_THREAD_NAME_MAX 15
  31. void uv_thread_set_name_np(uv_thread_t ut, const char* name);
  32. void os_thread_get_current_name_np(char threadname[NETDATA_THREAD_NAME_MAX + 1]);
  33. void webrtc_set_thread_name(void);
  34. #define netdata_thread_self pthread_self
  35. #define netdata_thread_testcancel pthread_testcancel
  36. #endif //NETDATA_THREADS_H