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-10-15 08:40:33 +04:00
|
|
|
#include <stdio.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),
|
2012-12-30 07:43:34 +04:00
|
|
|
fExecutedSubroutine(false),
|
2009-10-15 08:40:33 +04:00
|
|
|
fStoppedReason(THREAD_STOPPED_UNKNOWN),
|
2009-06-18 23:57:46 +04:00
|
|
|
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)
|
2010-12-16 16:50:30 +03:00
|
|
|
fCpuState->ReleaseReference();
|
2009-06-18 23:57:46 +04:00
|
|
|
if (fStackTrace != NULL)
|
2010-12-16 16:50:30 +03:00
|
|
|
fStackTrace->ReleaseReference();
|
2009-06-16 04:25:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
Thread::Init()
|
|
|
|
{
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-03 18:23:19 +04:00
|
|
|
bool
|
|
|
|
Thread::IsMainThread() const
|
|
|
|
{
|
|
|
|
return fID == fTeam->ID();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-16 04:25:36 +04:00
|
|
|
void
|
|
|
|
Thread::SetName(const BString& name)
|
|
|
|
{
|
|
|
|
fName = name;
|
|
|
|
}
|
2009-06-18 04:35:12 +04:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2009-10-15 08:40:33 +04:00
|
|
|
Thread::SetState(uint32 state, uint32 reason, const BString& info)
|
2009-06-18 04:35:12 +04:00
|
|
|
{
|
2012-11-24 21:46:21 +04:00
|
|
|
if (state == fState && reason == fStoppedReason)
|
2009-06-18 23:57:46 +04:00
|
|
|
return;
|
|
|
|
|
2009-06-18 04:35:12 +04:00
|
|
|
fState = state;
|
2009-10-15 08:40:33 +04:00
|
|
|
fStoppedReason = reason;
|
|
|
|
fStoppedReasonInfo = info;
|
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);
|
2012-12-30 07:43:34 +04:00
|
|
|
fExecutedSubroutine = false;
|
2009-06-18 23:57:46 +04:00
|
|
|
}
|
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)
|
2010-12-16 16:50:30 +03:00
|
|
|
fCpuState->ReleaseReference();
|
2009-06-18 23:57:46 +04:00
|
|
|
|
|
|
|
fCpuState = state;
|
|
|
|
|
|
|
|
if (fCpuState != NULL)
|
2010-12-16 16:50:30 +03:00
|
|
|
fCpuState->AcquireReference();
|
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)
|
2010-12-16 16:50:30 +03:00
|
|
|
fStackTrace->ReleaseReference();
|
2009-06-18 23:57:46 +04:00
|
|
|
|
|
|
|
fStackTrace = trace;
|
|
|
|
|
|
|
|
if (fStackTrace != NULL)
|
2010-12-16 16:50:30 +03:00
|
|
|
fStackTrace->AcquireReference();
|
2009-06-19 01:45:14 +04:00
|
|
|
|
|
|
|
fTeam->NotifyThreadStackTraceChanged(this);
|
2009-06-18 04:35:12 +04:00
|
|
|
}
|
2012-12-30 07:43:34 +04:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Thread::SetExecutedSubroutine()
|
|
|
|
{
|
|
|
|
fExecutedSubroutine = true;
|
|
|
|
}
|
|
|
|
|