headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / debugger / jobs / GetThreadStateJob.cpp
blob34d29dae7491892a44aa811c71cccc141e4afaaf
1 /*
2 * Copyright 2012-2016, Rene Gollent, rene@gollent.com.
3 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
5 */
7 #include "Jobs.h"
9 #include <AutoLocker.h>
11 #include "CpuState.h"
12 #include "DebuggerInterface.h"
13 #include "Team.h"
14 #include "Thread.h"
17 GetThreadStateJob::GetThreadStateJob(DebuggerInterface* debuggerInterface,
18 ::Thread* thread)
20 fKey(thread, JOB_TYPE_GET_THREAD_STATE),
21 fDebuggerInterface(debuggerInterface),
22 fThread(thread)
24 fThread->AcquireReference();
28 GetThreadStateJob::~GetThreadStateJob()
30 fThread->ReleaseReference();
34 const JobKey&
35 GetThreadStateJob::Key() const
37 return fKey;
41 status_t
42 GetThreadStateJob::Do()
44 CpuState* state = NULL;
45 status_t error = fDebuggerInterface->GetCpuState(fThread->ID(), state);
46 BReference<CpuState> reference(state, true);
48 AutoLocker<Team> locker(fThread->GetTeam());
50 if (fThread->State() != THREAD_STATE_UNKNOWN)
51 return B_OK;
53 if (error == B_OK) {
54 fThread->SetState(THREAD_STATE_STOPPED);
55 fThread->SetCpuState(state);
56 } else if (error == B_BAD_THREAD_STATE) {
57 fThread->SetState(THREAD_STATE_RUNNING);
58 } else
59 return error;
61 return B_OK;