ThreadCollection.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===-- ThreadCollection.h --------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLDB_TARGET_THREADCOLLECTION_H
  9. #define LLDB_TARGET_THREADCOLLECTION_H
  10. #include <mutex>
  11. #include <vector>
  12. #include "lldb/Utility/Iterable.h"
  13. #include "lldb/lldb-private.h"
  14. namespace lldb_private {
  15. class ThreadCollection {
  16. public:
  17. typedef std::vector<lldb::ThreadSP> collection;
  18. typedef LockingAdaptedIterable<collection, lldb::ThreadSP, vector_adapter,
  19. std::recursive_mutex>
  20. ThreadIterable;
  21. ThreadCollection();
  22. ThreadCollection(collection threads);
  23. virtual ~ThreadCollection() {}
  24. uint32_t GetSize();
  25. void AddThread(const lldb::ThreadSP &thread_sp);
  26. void AddThreadSortedByIndexID(const lldb::ThreadSP &thread_sp);
  27. void InsertThread(const lldb::ThreadSP &thread_sp, uint32_t idx);
  28. // Note that "idx" is not the same as the "thread_index". It is a zero based
  29. // index to accessing the current threads, whereas "thread_index" is a unique
  30. // index assigned
  31. lldb::ThreadSP GetThreadAtIndex(uint32_t idx);
  32. virtual ThreadIterable Threads() {
  33. return ThreadIterable(m_threads, GetMutex());
  34. }
  35. virtual std::recursive_mutex &GetMutex() const { return m_mutex; }
  36. protected:
  37. collection m_threads;
  38. mutable std::recursive_mutex m_mutex;
  39. };
  40. } // namespace lldb_private
  41. #endif // LLDB_TARGET_THREADCOLLECTION_H