Index: include/lldb/Target/ThreadCollection.h =================================================================== --- include/lldb/Target/ThreadCollection.h +++ include/lldb/Target/ThreadCollection.h @@ -0,0 +1,70 @@ +//===-- ThreadCollection.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_ThreadCollection_h_ +#define liblldb_ThreadCollection_h_ + +#include + +#include "lldb/lldb-private.h" +#include "lldb/Host/Mutex.h" +#include "lldb/Utility/Iterable.h" + +namespace lldb_private { + +class ThreadCollection +{ +public: + typedef std::vector collection; + typedef LockingAdaptedIterable ThreadIterable; + + ThreadCollection(); + + ThreadCollection(collection threads); + + virtual + ~ThreadCollection() + { + } + + uint32_t + GetSize(); + + void + AddThread (const lldb::ThreadSP &thread_sp); + + void + InsertThread (const lldb::ThreadSP &thread_sp, uint32_t idx); + + // Note that "idx" is not the same as the "thread_index". It is a zero + // based index to accessing the current threads, whereas "thread_index" + // is a unique index assigned + lldb::ThreadSP + GetThreadAtIndex (uint32_t idx); + + virtual ThreadIterable + Threads () + { + return ThreadIterable(m_threads, GetMutex()); + } + + virtual Mutex & + GetMutex() + { + return m_mutex; + } + +protected: + collection m_threads; + Mutex m_mutex; +}; + +} // namespace lldb_private + +#endif // liblldb_ThreadCollection_h_ Index: include/lldb/Target/ThreadList.h =================================================================== --- include/lldb/Target/ThreadList.h +++ include/lldb/Target/ThreadList.h @@ -15,16 +15,14 @@ #include "lldb/lldb-private.h" #include "lldb/Core/UserID.h" #include "lldb/Utility/Iterable.h" +#include "lldb/Target/ThreadCollection.h" - -// FIXME: Currently this is a thread list with lots of functionality for use only by -// the process for which this is the thread list. If we ever want a container class -// to hand out that is just a random subset of threads, with iterator functionality, -// then we should make that part a base class, and make a ProcessThreadList for the -// process. namespace lldb_private { -class ThreadList +// This is a thread list with lots of functionality for use only by the process +// for which this is the thread list. A generic container class with iterator +// functionality is ThreadCollection. +class ThreadList : public ThreadCollection { friend class Process; @@ -34,6 +32,7 @@ ThreadList (const ThreadList &rhs); + virtual ~ThreadList (); const ThreadList& @@ -42,11 +41,6 @@ uint32_t GetSize(bool can_update = true); - void - AddThread (const lldb::ThreadSP &thread_sp); - - void - InsertThread (const lldb::ThreadSP &thread_sp, uint32_t idx); // Return the selected thread if there is one. Otherwise, return the thread // selected at index 0. lldb::ThreadSP @@ -72,15 +66,6 @@ // is a unique index assigned lldb::ThreadSP GetThreadAtIndex (uint32_t idx, bool can_update = true); - - typedef std::vector collection; - typedef LockingAdaptedIterable ThreadIterable; - - ThreadIterable - Threads () - { - return ThreadIterable(m_threads, GetMutex()); - } lldb::ThreadSP FindThreadByID (lldb::tid_t tid, bool can_update = true); @@ -143,7 +128,7 @@ void SetStopID (uint32_t stop_id); - Mutex & + virtual Mutex & GetMutex (); void @@ -162,7 +147,6 @@ //------------------------------------------------------------------ Process *m_process; ///< The process that manages this thread list. uint32_t m_stop_id; ///< The process stop ID that this thread list is valid for. - collection m_threads; ///< The threads for this process. lldb::tid_t m_selected_tid; ///< For targets that need the notion of a current thread. private: Index: include/lldb/lldb-forward.h =================================================================== --- include/lldb/lldb-forward.h +++ include/lldb/lldb-forward.h @@ -226,6 +226,7 @@ class Target; class TargetList; class Thread; +class ThreadCollection; class ThreadList; class ThreadPlan; class ThreadPlanBase; @@ -381,6 +382,7 @@ typedef std::weak_ptr TargetWP; typedef std::shared_ptr ThreadSP; typedef std::weak_ptr ThreadWP; + typedef std::shared_ptr ThreadCollectionSP; typedef std::shared_ptr ThreadPlanSP; typedef std::shared_ptr ThreadPlanTracerSP; typedef std::shared_ptr TypeSP; Index: lldb.xcodeproj/project.pbxproj =================================================================== --- lldb.xcodeproj/project.pbxproj +++ lldb.xcodeproj/project.pbxproj @@ -620,6 +620,7 @@ 4CF52AF8142829390051E832 /* SBFileSpecList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CF52AF7142829390051E832 /* SBFileSpecList.cpp */; }; 8C2D6A53197A1EAF006989C9 /* MemoryHistory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8C2D6A52197A1EAF006989C9 /* MemoryHistory.cpp */; }; 8C2D6A5E197A250F006989C9 /* MemoryHistoryASan.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8C2D6A5A197A1FDC006989C9 /* MemoryHistoryASan.cpp */; }; + 8CCB017E19BA28A80009FD44 /* ThreadCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8CCB017A19BA283D0009FD44 /* ThreadCollection.cpp */; }; 94094C6B163B6F840083A547 /* ValueObjectCast.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94094C69163B6CD90083A547 /* ValueObjectCast.cpp */; }; 94145431175E63B500284436 /* lldb-versioning.h in Headers */ = {isa = PBXBuildFile; fileRef = 94145430175D7FDE00284436 /* lldb-versioning.h */; settings = {ATTRIBUTES = (Public, ); }; }; 941BCC7F14E48C4000BB969C /* SBTypeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 9461568614E355F2003A195C /* SBTypeFilter.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -1900,6 +1901,8 @@ 8C2D6A54197A1EBE006989C9 /* MemoryHistory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MemoryHistory.h; path = include/lldb/Target/MemoryHistory.h; sourceTree = ""; }; 8C2D6A5A197A1FDC006989C9 /* MemoryHistoryASan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryHistoryASan.cpp; sourceTree = ""; }; 8C2D6A5B197A1FDC006989C9 /* MemoryHistoryASan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryHistoryASan.h; sourceTree = ""; }; + 8CCB017A19BA283D0009FD44 /* ThreadCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadCollection.cpp; path = source/Target/ThreadCollection.cpp; sourceTree = ""; }; + 8CCB017C19BA289B0009FD44 /* ThreadCollection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ThreadCollection.h; path = include/lldb/Target/ThreadCollection.h; sourceTree = ""; }; 94005E0313F438DF001EF42D /* python-wrapper.swig */ = {isa = PBXFileReference; lastKnownFileType = text; path = "python-wrapper.swig"; sourceTree = ""; }; 94005E0513F45A1B001EF42D /* embedded_interpreter.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; name = embedded_interpreter.py; path = source/Interpreter/embedded_interpreter.py; sourceTree = ""; }; 94031A9F13CF5B3D00DCFF3C /* PriorityPointerPair.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PriorityPointerPair.h; path = include/lldb/Utility/PriorityPointerPair.h; sourceTree = ""; }; @@ -3711,6 +3714,8 @@ 26BC7F3C10F1B90C00F91463 /* TargetList.cpp */, 26BC7DFA10F1B81A00F91463 /* Thread.h */, 26BC7F3D10F1B90C00F91463 /* Thread.cpp */, + 8CCB017C19BA289B0009FD44 /* ThreadCollection.h */, + 8CCB017A19BA283D0009FD44 /* ThreadCollection.cpp */, 26BC7DFB10F1B81A00F91463 /* ThreadList.h */, 26BC7F3E10F1B90C00F91463 /* ThreadList.cpp */, 26BC7DFC10F1B81A00F91463 /* ThreadPlan.h */, @@ -4921,6 +4926,7 @@ 2689005413353E0400698AC0 /* UserSettingsController.cpp in Sources */, 2689005513353E0400698AC0 /* UUID.cpp in Sources */, 23059A0719532B96007B8189 /* LinuxSignals.cpp in Sources */, + 8CCB017E19BA28A80009FD44 /* ThreadCollection.cpp in Sources */, 2689005613353E0400698AC0 /* Value.cpp in Sources */, 2689005713353E0400698AC0 /* ValueObject.cpp in Sources */, 2689005813353E0400698AC0 /* ValueObjectChild.cpp in Sources */, Index: source/Target/ThreadCollection.cpp =================================================================== --- source/Target/ThreadCollection.cpp +++ source/Target/ThreadCollection.cpp @@ -0,0 +1,62 @@ +//===-- ThreadCollection.cpp ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include + +#include + +#include "lldb/Target/ThreadCollection.h" + +using namespace lldb; +using namespace lldb_private; + +ThreadCollection::ThreadCollection() : +m_threads(), +m_mutex() +{ +} + +ThreadCollection::ThreadCollection(collection threads) : +m_threads(threads), +m_mutex() +{ +} + +void +ThreadCollection::AddThread (const ThreadSP &thread_sp) +{ + Mutex::Locker locker(GetMutex()); + m_threads.push_back (thread_sp); +} + +void +ThreadCollection::InsertThread (const lldb::ThreadSP &thread_sp, uint32_t idx) +{ + Mutex::Locker locker(GetMutex()); + if (idx < m_threads.size()) + m_threads.insert(m_threads.begin() + idx, thread_sp); + else + m_threads.push_back (thread_sp); +} + +uint32_t +ThreadCollection::GetSize () +{ + Mutex::Locker locker(GetMutex()); + return m_threads.size(); +} + +ThreadSP +ThreadCollection::GetThreadAtIndex (uint32_t idx) +{ + Mutex::Locker locker(GetMutex()); + ThreadSP thread_sp; + if (idx < m_threads.size()) + thread_sp = m_threads[idx]; + return thread_sp; +} Index: source/Target/ThreadList.cpp =================================================================== --- source/Target/ThreadList.cpp +++ source/Target/ThreadList.cpp @@ -22,17 +22,17 @@ using namespace lldb_private; ThreadList::ThreadList (Process *process) : + ThreadCollection(), m_process (process), m_stop_id (0), - m_threads(), m_selected_tid (LLDB_INVALID_THREAD_ID) { } ThreadList::ThreadList (const ThreadList &rhs) : + ThreadCollection(), m_process (rhs.m_process), m_stop_id (rhs.m_stop_id), - m_threads (), m_selected_tid () { // Use the assignment operator since it uses the mutex @@ -77,25 +77,6 @@ m_stop_id = stop_id; } - -void -ThreadList::AddThread (const ThreadSP &thread_sp) -{ - Mutex::Locker locker(GetMutex()); - m_threads.push_back(thread_sp); -} - -void -ThreadList::InsertThread (const lldb::ThreadSP &thread_sp, uint32_t idx) -{ - Mutex::Locker locker(GetMutex()); - if (idx < m_threads.size()) - m_threads.insert(m_threads.begin() + idx, thread_sp); - else - m_threads.push_back (thread_sp); -} - - uint32_t ThreadList::GetSize (bool can_update) {