thread.h 1.5 KB

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