2 * Copyright 2013-2016, Rene Gollent, rene@gollent.com.
3 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
7 #include "model/Thread.h"
12 #include "StackTrace.h"
16 Thread::Thread(Team
* team
, thread_id threadID
)
20 fState(THREAD_STATE_UNKNOWN
),
21 fReturnValueInfos(NULL
),
22 fStopRequestPending(false),
23 fStoppedReason(THREAD_STOPPED_UNKNOWN
),
32 if (fCpuState
!= NULL
)
33 fCpuState
->ReleaseReference();
34 if (fStackTrace
!= NULL
)
35 fStackTrace
->ReleaseReference();
37 ClearReturnValueInfos();
38 delete fReturnValueInfos
;
45 fReturnValueInfos
= new(std::nothrow
) ReturnValueInfoList
;
46 if (fReturnValueInfos
== NULL
)
54 Thread::IsMainThread() const
56 return fID
== fTeam
->ID();
61 Thread::SetName(const BString
& name
)
68 Thread::SetState(uint32 state
, uint32 reason
, const BString
& info
)
70 if (state
== fState
&& reason
== fStoppedReason
)
74 fStoppedReason
= reason
;
75 fStoppedReasonInfo
= info
;
77 // unset CPU state and stack trace, if the thread isn't stopped
78 if (fState
!= THREAD_STATE_STOPPED
) {
81 ClearReturnValueInfos();
82 fStopRequestPending
= false;
85 fTeam
->NotifyThreadStateChanged(this);
90 Thread::SetCpuState(CpuState
* state
)
92 if (state
== fCpuState
)
95 if (fCpuState
!= NULL
)
96 fCpuState
->ReleaseReference();
100 if (fCpuState
!= NULL
)
101 fCpuState
->AcquireReference();
103 fTeam
->NotifyThreadCpuStateChanged(this);
108 Thread::SetStackTrace(StackTrace
* trace
)
110 if (trace
== fStackTrace
)
113 if (fStackTrace
!= NULL
)
114 fStackTrace
->ReleaseReference();
118 if (fStackTrace
!= NULL
)
119 fStackTrace
->AcquireReference();
121 fTeam
->NotifyThreadStackTraceChanged(this);
125 Thread::SetStopRequestPending()
127 fStopRequestPending
= true;
132 Thread::AddReturnValueInfo(ReturnValueInfo
* info
)
134 if (!fReturnValueInfos
->AddItem(info
))
137 info
->AcquireReference();
143 Thread::ClearReturnValueInfos()
145 for (int32 i
= 0; i
< fReturnValueInfos
->CountItems(); i
++)
146 fReturnValueInfos
->ItemAt(i
)->ReleaseReference();
148 fReturnValueInfos
->MakeEmpty();