Model::Thread* Model::AddThread(const system_profiler_thread_added* event, nanotime_t time) { // check whether we do already know the thread Thread* thread = ThreadByID(event->thread); if (thread != NULL) { fprintf(stderr, "Duplicate thread: %ld\n", event->thread); // TODO: User feedback! return thread; } // get its team Team* team = TeamByID(event->team); if (team == NULL) { fprintf(stderr, "No team for thread: %ld\n", event->thread); return NULL; } // create the thread and add it thread = new(std::nothrow) Thread(team, event, time); if (thread == NULL) return NULL; ObjectDeleter<Thread> threadDeleter(thread); if (!fThreads.BinaryInsert(thread, &Thread::CompareByID)) return NULL; if (!team->AddThread(thread)) { fThreads.RemoveItem(thread); return NULL; } threadDeleter.Detach(); return thread; }
Model::ThreadWaitObjectGroup* Model::ThreadWaitObjectGroupFor(thread_id threadID, uint32 type, addr_t object) const { Thread* thread = ThreadByID(threadID); if (thread == NULL) return NULL; return thread->ThreadWaitObjectGroupFor(type, object); }
Model::ThreadWaitObject* Model::AddThreadWaitObject(thread_id threadID, WaitObject* waitObject, ThreadWaitObjectGroup** _threadWaitObjectGroup) { Thread* thread = ThreadByID(threadID); if (thread == NULL) return NULL; return thread->AddThreadWaitObject(waitObject, _threadWaitObjectGroup); }
bool Team::RemoveThread(thread_id threadID) { Thread* thread = ThreadByID(threadID); if (thread == NULL) return false; RemoveThread(thread); thread->ReleaseReference(); return true; }