thread.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 pid_; /* Not all tools update this */
  14. pid_t tid;
  15. pid_t ppid;
  16. char shortname[3];
  17. bool comm_set;
  18. bool dead; /* if set thread has exited */
  19. char *comm;
  20. int comm_len;
  21. void *priv;
  22. };
  23. struct machine;
  24. struct thread *thread__new(pid_t pid, pid_t tid);
  25. void thread__delete(struct thread *self);
  26. static inline void thread__exited(struct thread *thread)
  27. {
  28. thread->dead = true;
  29. }
  30. int thread__set_comm(struct thread *self, const char *comm);
  31. int thread__comm_len(struct thread *self);
  32. void thread__insert_map(struct thread *self, struct map *map);
  33. int thread__fork(struct thread *self, struct thread *parent);
  34. size_t thread__fprintf(struct thread *thread, FILE *fp);
  35. static inline struct map *thread__find_map(struct thread *self,
  36. enum map_type type, u64 addr)
  37. {
  38. return self ? map_groups__find(&self->mg, type, addr) : NULL;
  39. }
  40. void thread__find_addr_map(struct thread *thread, struct machine *machine,
  41. u8 cpumode, enum map_type type, u64 addr,
  42. struct addr_location *al);
  43. void thread__find_addr_location(struct thread *thread, struct machine *machine,
  44. u8 cpumode, enum map_type type, u64 addr,
  45. struct addr_location *al);
  46. static inline void *thread__priv(struct thread *thread)
  47. {
  48. return thread->priv;
  49. }
  50. static inline void thread__set_priv(struct thread *thread, void *p)
  51. {
  52. thread->priv = p;
  53. }
  54. #endif /* __PERF_THREAD_H */