xref: /haiku/src/kits/debugger/jobs/GetCPUStateJob.cpp (revision fce4895d1884da5ae6fb299d23c735c598e690b1)
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  */
6 
7 #include "Jobs.h"
8 
9 #include <AutoLocker.h>
10 
11 #include "CpuState.h"
12 #include "DebuggerInterface.h"
13 #include "Team.h"
14 #include "Thread.h"
15 
16 
GetCpuStateJob(DebuggerInterface * debuggerInterface,::Thread * thread)17 GetCpuStateJob::GetCpuStateJob(DebuggerInterface* debuggerInterface,
18 	::Thread* thread)
19 	:
20 	fKey(thread, JOB_TYPE_GET_CPU_STATE),
21 	fDebuggerInterface(debuggerInterface),
22 	fThread(thread)
23 {
24 	fThread->AcquireReference();
25 }
26 
27 
~GetCpuStateJob()28 GetCpuStateJob::~GetCpuStateJob()
29 {
30 	fThread->ReleaseReference();
31 }
32 
33 
34 const JobKey&
Key() const35 GetCpuStateJob::Key() const
36 {
37 	return fKey;
38 }
39 
40 
41 status_t
Do()42 GetCpuStateJob::Do()
43 {
44 	CpuState* state;
45 	status_t error = fDebuggerInterface->GetCpuState(fThread->ID(), state);
46 	if (error != B_OK)
47 		return error;
48 	BReference<CpuState> reference(state, true);
49 
50 	AutoLocker<Team> locker(fThread->GetTeam());
51 
52 	if (fThread->State() == THREAD_STATE_STOPPED)
53 		fThread->SetCpuState(state);
54 
55 	return B_OK;
56 }
57