thread.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef __PERF_THREAD_H
  2. #define __PERF_THREAD_H
  3. #include <linux/rbtree.h>
  4. #include <linux/list.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include "symbol.h"
  8. struct thread {
  9. union {
  10. struct rb_node rb_node;
  11. struct list_head node;
  12. };
  13. struct map_groups mg;
  14. pid_t pid_; /* Not all tools update this */
  15. pid_t tid;
  16. pid_t ppid;
  17. char shortname[3];
  18. bool comm_set;
  19. bool dead; /* if set thread has exited */
  20. struct list_head comm_list;
  21. int comm_len;
  22. void *priv;
  23. };
  24. struct machine;
  25. struct comm;
  26. struct thread *thread__new(pid_t pid, pid_t tid);
  27. void thread__delete(struct thread *thread);
  28. static inline void thread__exited(struct thread *thread)
  29. {
  30. thread->dead = true;
  31. }
  32. int thread__set_comm(struct thread *thread, const char *comm, u64 timestamp);
  33. int thread__comm_len(struct thread *thread);
  34. struct comm *thread__comm(const struct thread *thread);
  35. const char *thread__comm_str(const struct thread *thread);
  36. void thread__insert_map(struct thread *thread, struct map *map);
  37. int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
  38. size_t thread__fprintf(struct thread *thread, FILE *fp);
  39. static inline struct map *thread__find_map(struct thread *thread,
  40. enum map_type type, u64 addr)
  41. {
  42. return thread ? map_groups__find(&thread->mg, type, addr) : NULL;
  43. }
  44. void thread__find_addr_map(struct thread *thread, struct machine *machine,
  45. u8 cpumode, enum map_type type, u64 addr,
  46. struct addr_location *al);
  47. void thread__find_addr_location(struct thread *thread, struct machine *machine,
  48. u8 cpumode, enum map_type type, u64 addr,
  49. struct addr_location *al);
  50. static inline void *thread__priv(struct thread *thread)
  51. {
  52. return thread->priv;
  53. }
  54. static inline void thread__set_priv(struct thread *thread, void *p)
  55. {
  56. thread->priv = p;
  57. }
  58. #endif /* __PERF_THREAD_H */