1/*
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.
5 */
6#ifndef THREAD_H
7#define THREAD_H
8
9#include <OS.h>
10#include <String.h>
11
12#include <Referenceable.h>
13#include <util/DoublyLinkedList.h>
14
15#include "ReturnValueInfo.h"
16#include "types/Types.h"
17
18
19class CpuState;
20class StackTrace;
21class Team;
22
23
24// general thread state
25enum {
26	THREAD_STATE_UNKNOWN,
27	THREAD_STATE_RUNNING,
28	THREAD_STATE_STOPPED
29};
30
31// reason why stopped
32enum {
33	THREAD_STOPPED_UNKNOWN,
34	THREAD_STOPPED_DEBUGGED,
35	THREAD_STOPPED_DEBUGGER_CALL,
36	THREAD_STOPPED_BREAKPOINT,
37	THREAD_STOPPED_WATCHPOINT,
38	THREAD_STOPPED_SINGLE_STEP,
39	THREAD_STOPPED_EXCEPTION
40};
41
42
43class Thread : public BReferenceable,
44	public DoublyLinkedListLinkImpl< ::Thread> {
45public:
46								Thread(Team* team, thread_id threadID);
47								~Thread();
48
49			status_t			Init();
50
51			Team*				GetTeam() const	{ return fTeam; }
52			thread_id			ID() const		{ return fID; }
53
54			bool				IsMainThread() const;
55
56			const char*			Name() const	{ return fName.String(); }
57			void				SetName(const BString& name);
58
59			uint32				State() const	{ return fState; }
60			void				SetState(uint32 state,
61									uint32 reason = THREAD_STOPPED_UNKNOWN,
62									const BString& info = BString());
63
64			uint32				StoppedReason() const
65									{ return fStoppedReason; }
66			const BString&		StoppedReasonInfo() const
67									{ return fStoppedReasonInfo; }
68
69			CpuState*			GetCpuState() const	{ return fCpuState; }
70			void				SetCpuState(CpuState* state);
71
72			StackTrace*			GetStackTrace() const	{ return fStackTrace; }
73			void				SetStackTrace(StackTrace* trace);
74
75			bool				StopRequestPending() const
76									{ return fStopRequestPending; }
77			void				SetStopRequestPending();
78
79			ReturnValueInfoList*
80								ReturnValueInfos() const
81								{ return fReturnValueInfos; }
82			status_t			AddReturnValueInfo(ReturnValueInfo* info);
83			void				ClearReturnValueInfos();
84
85private:
86			Team*				fTeam;
87			thread_id			fID;
88			BString				fName;
89			uint32				fState;
90			ReturnValueInfoList*
91								fReturnValueInfos;
92			bool				fStopRequestPending;
93			uint32				fStoppedReason;
94			BString				fStoppedReasonInfo;
95			CpuState*			fCpuState;
96			StackTrace*			fStackTrace;
97};
98
99
100typedef DoublyLinkedList< ::Thread> ThreadList;
101
102
103#endif	// THREAD_H
104