2009-06-16 04:25:36 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Thread.h"
|
|
|
|
|
2009-06-18 23:57:46 +04:00
|
|
|
#include "CpuState.h"
|
|
|
|
#include "StackTrace.h"
|
2009-06-19 01:45:14 +04:00
|
|
|
#include "Team.h"
|
2009-06-18 23:57:46 +04:00
|
|
|
|
2009-06-16 04:25:36 +04:00
|
|
|
|
2009-06-18 04:35:12 +04:00
|
|
|
Thread::Thread(Team* team, thread_id threadID)
|
2009-06-16 04:25:36 +04:00
|
|
|
:
|
2009-06-18 04:35:12 +04:00
|
|
|
fTeam(team),
|
|
|
|
fID(threadID),
|
2009-06-18 23:57:46 +04:00
|
|
|
fState(THREAD_STATE_UNKNOWN),
|
|
|
|
fCpuState(NULL),
|
|
|
|
fStackTrace(NULL)
|
2009-06-16 04:25:36 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Thread::~Thread()
|
|
|
|
{
|
2009-06-18 23:57:46 +04:00
|
|
|
if (fCpuState != NULL)
|
|
|
|
fCpuState->RemoveReference();
|
|
|
|
if (fStackTrace != NULL)
|
|
|
|
fStackTrace->RemoveReference();
|
2009-06-16 04:25:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
Thread::Init()
|
|
|
|
{
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Thread::SetName(const BString& name)
|
|
|
|
{
|
|
|
|
fName = name;
|
|
|
|
}
|
2009-06-18 04:35:12 +04:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Thread::SetState(uint32 state)
|
|
|
|
{
|
2009-06-18 23:57:46 +04:00
|
|
|
if (state == fState)
|
|
|
|
return;
|
|
|
|
|
2009-06-18 04:35:12 +04:00
|
|
|
fState = state;
|
2009-06-18 23:57:46 +04:00
|
|
|
|
|
|
|
// unset CPU state and stack trace, if the thread isn't stopped
|
|
|
|
if (fState != THREAD_STATE_STOPPED) {
|
|
|
|
SetCpuState(NULL);
|
|
|
|
SetStackTrace(NULL);
|
|
|
|
}
|
2009-06-19 01:45:14 +04:00
|
|
|
|
|
|
|
fTeam->NotifyThreadStateChanged(this);
|
2009-06-18 23:57:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Thread::SetCpuState(CpuState* state)
|
|
|
|
{
|
|
|
|
if (state == fCpuState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fCpuState != NULL)
|
|
|
|
fCpuState->RemoveReference();
|
|
|
|
|
|
|
|
fCpuState = state;
|
|
|
|
|
|
|
|
if (fCpuState != NULL)
|
|
|
|
fCpuState->AddReference();
|
2009-06-19 01:45:14 +04:00
|
|
|
|
|
|
|
fTeam->NotifyThreadCpuStateChanged(this);
|
2009-06-18 23:57:46 +04:00
|
|
|
}
|
|
|
|
|
2009-06-19 01:45:14 +04:00
|
|
|
|
2009-06-18 23:57:46 +04:00
|
|
|
void
|
|
|
|
Thread::SetStackTrace(StackTrace* trace)
|
|
|
|
{
|
|
|
|
if (trace == fStackTrace)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fStackTrace != NULL)
|
|
|
|
fStackTrace->RemoveReference();
|
|
|
|
|
|
|
|
fStackTrace = trace;
|
|
|
|
|
|
|
|
if (fStackTrace != NULL)
|
|
|
|
fStackTrace->AddReference();
|
2009-06-19 01:45:14 +04:00
|
|
|
|
|
|
|
fTeam->NotifyThreadStackTraceChanged(this);
|
2009-06-18 04:35:12 +04:00
|
|
|
}
|