1278332Semaste//===-- ThreadCollection.h --------------------------------------*- C++ -*-===//
2278332Semaste//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6278332Semaste//
7278332Semaste//===----------------------------------------------------------------------===//
8278332Semaste
9278332Semaste#ifndef liblldb_ThreadCollection_h_
10278332Semaste#define liblldb_ThreadCollection_h_
11278332Semaste
12309124Sdim#include <mutex>
13278332Semaste#include <vector>
14278332Semaste
15314564Sdim#include "lldb/Utility/Iterable.h"
16278332Semaste#include "lldb/lldb-private.h"
17278332Semaste
18278332Semastenamespace lldb_private {
19314564Sdim
20314564Sdimclass ThreadCollection {
21278332Semastepublic:
22314564Sdim  typedef std::vector<lldb::ThreadSP> collection;
23314564Sdim  typedef LockingAdaptedIterable<collection, lldb::ThreadSP, vector_adapter,
24314564Sdim                                 std::recursive_mutex>
25314564Sdim      ThreadIterable;
26309124Sdim
27314564Sdim  ThreadCollection();
28309124Sdim
29314564Sdim  ThreadCollection(collection threads);
30309124Sdim
31314564Sdim  virtual ~ThreadCollection() {}
32278332Semaste
33314564Sdim  uint32_t GetSize();
34309124Sdim
35314564Sdim  void AddThread(const lldb::ThreadSP &thread_sp);
36309124Sdim
37314564Sdim  void AddThreadSortedByIndexID(const lldb::ThreadSP &thread_sp);
38314564Sdim
39314564Sdim  void InsertThread(const lldb::ThreadSP &thread_sp, uint32_t idx);
40314564Sdim
41341825Sdim  // Note that "idx" is not the same as the "thread_index". It is a zero based
42341825Sdim  // index to accessing the current threads, whereas "thread_index" is a unique
43341825Sdim  // index assigned
44314564Sdim  lldb::ThreadSP GetThreadAtIndex(uint32_t idx);
45314564Sdim
46314564Sdim  virtual ThreadIterable Threads() {
47314564Sdim    return ThreadIterable(m_threads, GetMutex());
48314564Sdim  }
49314564Sdim
50314564Sdim  virtual std::recursive_mutex &GetMutex() const { return m_mutex; }
51314564Sdim
52278332Semasteprotected:
53314564Sdim  collection m_threads;
54314564Sdim  mutable std::recursive_mutex m_mutex;
55278332Semaste};
56314564Sdim
57278332Semaste} // namespace lldb_private
58278332Semaste
59314564Sdim#endif // liblldb_ThreadCollection_h_
60