Move the ivars / logic of SBQueue into a QueueImpl class and

change SBQueue to have a shared pointer to its corresponding
QueueImpl object for binary compatibility.
<rdar://problem/15657926> 

llvm-svn: 197300
This commit is contained in:
Jason Molenda 2013-12-14 01:14:45 +00:00
parent 6ed7251683
commit c8064ac626
5 changed files with 283 additions and 170 deletions

View File

@ -322,7 +322,7 @@ protected:
friend class SBTarget;
friend class SBThread;
friend class SBValue;
friend class SBQueue;
friend class lldb_private::QueueImpl;
lldb::ProcessSP
GetSP() const;

View File

@ -25,6 +25,11 @@ public:
SBQueue (const QueueSP& queue_sp);
SBQueue (const SBQueue& rhs);
const SBQueue &
operator= (const lldb::SBQueue& rhs);
~SBQueue();
bool
@ -70,11 +75,7 @@ protected:
FetchItems ();
private:
lldb::QueueWP m_queue_wp;
std::vector<lldb::ThreadWP> m_threads; // threads currently executing this queue's items
bool m_thread_list_fetched; // have we tried to fetch the threads list already?
std::vector<lldb::QueueItemSP> m_items; // items currently enqueued
bool m_queue_items_fetched; // have we tried to fetch the item list already?
std::shared_ptr<lldb_private::QueueImpl> m_opaque_sp;
};
} // namespace lldb

View File

@ -214,7 +214,7 @@ protected:
friend class SBProcess;
friend class SBDebugger;
friend class SBValue;
friend class SBQueue;
friend class lldb_private::QueueImpl;
friend class SBQueueItem;
void

View File

@ -218,6 +218,7 @@ class ScriptedSyntheticChildren;
#endif
class Queue;
class QueueItem;
class QueueImpl;
class Target;
class TargetList;
class Thread;

View File

@ -22,235 +22,346 @@
using namespace lldb;
using namespace lldb_private;
//----------------------------------------------------------------------
// Constructors
//----------------------------------------------------------------------
namespace lldb_private
{
class QueueImpl
{
public:
QueueImpl () :
m_queue_wp(),
m_threads(),
m_thread_list_fetched(false),
m_items(),
m_queue_items_fetched(false)
{
}
QueueImpl (const lldb::QueueSP &queue_sp) :
m_queue_wp(queue_sp),
m_threads(),
m_thread_list_fetched(false),
m_items(),
m_queue_items_fetched(false)
{
}
QueueImpl (const QueueImpl &rhs)
{
if (&rhs == this)
return;
m_queue_wp = rhs.m_queue_wp;
m_threads = rhs.m_threads;
m_thread_list_fetched = rhs.m_thread_list_fetched;
m_items = rhs.m_items;
m_queue_items_fetched = rhs.m_queue_items_fetched;
}
~QueueImpl ()
{
}
bool
IsValid ()
{
return m_queue_wp.lock() != NULL;
}
void
Clear ()
{
m_queue_wp.reset();
m_thread_list_fetched = false;
m_threads.clear();
m_queue_items_fetched = false;
m_items.clear();
}
void
SetQueue (const lldb::QueueSP &queue_sp)
{
Clear();
m_queue_wp = queue_sp;
}
lldb::queue_id_t
GetQueueID () const
{
lldb::queue_id_t result = LLDB_INVALID_QUEUE_ID;
lldb::QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
result = queue_sp->GetID();
}
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (log)
log->Printf ("SBQueue(%p)::GetQueueID () => 0x%" PRIx64, this, result);
return result;
}
uint32_t
GetIndexID () const
{
uint32_t result = LLDB_INVALID_INDEX32;
lldb::QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
result = queue_sp->GetIndexID();
}
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (log)
log->Printf ("SBQueueImpl(%p)::GetIndexID () => %d", this, result);
return result;
}
const char *
GetName () const
{
const char *name = NULL;
lldb::QueueSP queue_sp = m_queue_wp.lock ();
if (queue_sp.get())
{
name = queue_sp->GetName();
}
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (log)
log->Printf ("SBQueueImpl(%p)::GetName () => %s", this, name ? name : "NULL");
return name;
}
void
FetchThreads ()
{
if (m_thread_list_fetched == false)
{
lldb::QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
Process::StopLocker stop_locker;
if (stop_locker.TryLock (&queue_sp->GetProcess()->GetRunLock()))
{
const std::vector<ThreadSP> thread_list(queue_sp->GetThreads());
m_thread_list_fetched = true;
const uint32_t num_threads = thread_list.size();
for (uint32_t idx = 0; idx < num_threads; ++idx)
{
ThreadSP thread_sp = thread_list[idx];
if (thread_sp && thread_sp->IsValid())
{
m_threads.push_back (thread_sp);
}
}
}
}
}
}
void
FetchItems ()
{
if (m_queue_items_fetched == false)
{
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
Process::StopLocker stop_locker;
if (stop_locker.TryLock (&queue_sp->GetProcess()->GetRunLock()))
{
const std::vector<QueueItemSP> queue_items(queue_sp->GetItems());
m_queue_items_fetched = true;
const uint32_t num_items = queue_items.size();
for (uint32_t idx = 0; idx < num_items; ++idx)
{
QueueItemSP item = queue_items[idx];
if (item && item->IsValid())
{
m_items.push_back (item);
}
}
}
}
}
}
uint32_t
GetNumThreads ()
{
uint32_t result = 0;
FetchThreads();
if (m_thread_list_fetched)
{
result = m_threads.size();
}
return result;
}
lldb::SBThread
GetThreadAtIndex (uint32_t idx)
{
FetchThreads();
SBThread sb_thread;
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp && idx < m_threads.size())
{
ProcessSP process_sp = queue_sp->GetProcess();
if (process_sp)
{
ThreadSP thread_sp = m_threads[idx].lock();
if (thread_sp)
{
sb_thread.SetThread (thread_sp);
}
}
}
return sb_thread;
}
uint32_t
GetNumItems ()
{
uint32_t result = 0;
FetchItems();
if (m_queue_items_fetched)
{
result = m_items.size();
}
return result;
}
lldb::SBQueueItem
GetItemAtIndex (uint32_t idx)
{
SBQueueItem result;
FetchItems();
if (m_queue_items_fetched && idx < m_items.size())
{
result.SetQueueItem (m_items[idx]);
}
return result;
}
lldb::SBProcess
GetProcess ()
{
SBProcess result;
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
result.SetSP (queue_sp->GetProcess());
}
return result;
}
private:
lldb::QueueWP m_queue_wp;
std::vector<lldb::ThreadWP> m_threads; // threads currently executing this queue's items
bool m_thread_list_fetched; // have we tried to fetch the threads list already?
std::vector<lldb::QueueItemSP> m_items; // items currently enqueued
bool m_queue_items_fetched; // have we tried to fetch the item list already?
};
}
SBQueue::SBQueue () :
m_queue_wp(),
m_threads(),
m_thread_list_fetched(false),
m_items(),
m_queue_items_fetched(false)
m_opaque_sp (new QueueImpl())
{
}
SBQueue::SBQueue (const QueueSP& queue_sp) :
m_queue_wp(queue_sp),
m_threads(),
m_thread_list_fetched(false),
m_items(),
m_queue_items_fetched(false)
m_opaque_sp (new QueueImpl (queue_sp))
{
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
SBQueue::SBQueue (const SBQueue &rhs)
{
if (&rhs == this)
return;
m_opaque_sp = rhs.m_opaque_sp;
}
const lldb::SBQueue &
SBQueue::operator = (const lldb::SBQueue &rhs)
{
m_opaque_sp = rhs.m_opaque_sp;
return *this;
}
SBQueue::~SBQueue()
{
m_threads.clear();
m_items.clear();
}
bool
SBQueue::IsValid() const
{
QueueSP queue_sp = m_queue_wp.lock();
return queue_sp.get() != NULL;
return m_opaque_sp->IsValid();
}
void
SBQueue::Clear ()
{
m_queue_wp.reset();
m_thread_list_fetched = false;
m_threads.clear();
m_queue_items_fetched = false;
m_items.clear();
m_opaque_sp->Clear();
}
void
SBQueue::SetQueue (const QueueSP& queue_sp)
{
m_queue_wp = queue_sp;
m_thread_list_fetched = false;
m_threads.clear();
m_queue_items_fetched = false;
m_items.clear();
m_opaque_sp->SetQueue (queue_sp);
}
lldb::queue_id_t
SBQueue::GetQueueID () const
{
queue_id_t result = LLDB_INVALID_QUEUE_ID;
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
result = queue_sp->GetID();
}
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (log)
log->Printf ("SBQueue(%p)::GetQueueID () => 0x%" PRIx64, this, result);
return result;
return m_opaque_sp->GetQueueID ();
}
uint32_t
SBQueue::GetIndexID () const
{
uint32_t result = LLDB_INVALID_INDEX32;
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
result = queue_sp->GetIndexID();
}
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (log)
log->Printf ("SBQueue(%p)::GetIndexID () => %d", this, result);
return result;
return m_opaque_sp->GetIndexID ();
}
const char *
SBQueue::GetName () const
{
const char *name = NULL;
QueueSP queue_sp = m_queue_wp.lock ();
if (queue_sp.get())
{
name = queue_sp->GetName();
}
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (log)
log->Printf ("SBQueue(%p)::GetName () => %s", this, name ? name : "NULL");
return name;
}
void
SBQueue::FetchThreads ()
{
if (m_thread_list_fetched == false)
{
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
Process::StopLocker stop_locker;
if (stop_locker.TryLock (&queue_sp->GetProcess()->GetRunLock()))
{
const std::vector<ThreadSP> thread_list(queue_sp->GetThreads());
m_thread_list_fetched = true;
const uint32_t num_threads = thread_list.size();
for (uint32_t idx = 0; idx < num_threads; ++idx)
{
ThreadSP thread_sp = thread_list[idx];
if (thread_sp && thread_sp->IsValid())
{
m_threads.push_back (thread_sp);
}
}
}
}
}
}
void
SBQueue::FetchItems ()
{
if (m_queue_items_fetched == false)
{
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
Process::StopLocker stop_locker;
if (stop_locker.TryLock (&queue_sp->GetProcess()->GetRunLock()))
{
const std::vector<QueueItemSP> queue_items(queue_sp->GetItems());
m_queue_items_fetched = true;
const uint32_t num_items = queue_items.size();
for (uint32_t idx = 0; idx < num_items; ++idx)
{
QueueItemSP item = queue_items[idx];
if (item && item->IsValid())
{
m_items.push_back (item);
}
}
}
}
}
return m_opaque_sp->GetName ();
}
uint32_t
SBQueue::GetNumThreads ()
{
uint32_t result = 0;
FetchThreads();
if (m_thread_list_fetched)
{
result = m_threads.size();
}
return result;
return m_opaque_sp->GetNumThreads ();
}
SBThread
SBQueue::GetThreadAtIndex (uint32_t idx)
{
FetchThreads();
SBThread sb_thread;
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp && idx < m_threads.size())
{
ProcessSP process_sp = queue_sp->GetProcess();
if (process_sp)
{
ThreadSP thread_sp = m_threads[idx].lock();
if (thread_sp)
{
sb_thread.SetThread (thread_sp);
}
}
}
return sb_thread;
return m_opaque_sp->GetThreadAtIndex (idx);
}
uint32_t
SBQueue::GetNumItems ()
{
uint32_t result = 0;
FetchItems();
if (m_queue_items_fetched)
{
result = m_items.size();
}
return result;
return m_opaque_sp->GetNumItems ();
}
SBQueueItem
SBQueue::GetItemAtIndex (uint32_t idx)
{
SBQueueItem result;
FetchItems();
if (m_queue_items_fetched && idx < m_items.size())
{
result.SetQueueItem (m_items[idx]);
}
return result;
return m_opaque_sp->GetItemAtIndex (idx);
}
SBProcess
SBQueue::GetProcess ()
{
SBProcess result;
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
result.SetSP (queue_sp->GetProcess());
}
return result;
return m_opaque_sp->GetProcess();
}