threads.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PERF_THREADS_H
  3. #define __PERF_THREADS_H
  4. #include "hashmap.h"
  5. #include "rwsem.h"
  6. struct thread;
  7. #define THREADS__TABLE_BITS 3
  8. #define THREADS__TABLE_SIZE (1 << THREADS__TABLE_BITS)
  9. struct threads_table_entry {
  10. /* Key is tid, value is struct thread. */
  11. struct hashmap shard;
  12. struct rw_semaphore lock;
  13. struct thread *last_match;
  14. };
  15. struct threads {
  16. struct threads_table_entry table[THREADS__TABLE_SIZE];
  17. };
  18. void threads__init(struct threads *threads);
  19. void threads__exit(struct threads *threads);
  20. size_t threads__nr(struct threads *threads);
  21. struct thread *threads__find(struct threads *threads, pid_t tid);
  22. struct thread *threads__findnew(struct threads *threads, pid_t pid, pid_t tid, bool *created);
  23. void threads__remove_all_threads(struct threads *threads);
  24. void threads__remove(struct threads *threads, struct thread *thread);
  25. int threads__for_each_thread(struct threads *threads,
  26. int (*fn)(struct thread *thread, void *data),
  27. void *data);
  28. #endif /* __PERF_THREADS_H */