1/*
2 * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef THREAD_H
6#define THREAD_H
7
8
9#include <String.h>
10
11#include <util/DoublyLinkedList.h>
12
13#include "ProfiledEntity.h"
14#include "ProfileResult.h"
15
16
17class Image;
18class Team;
19
20
21class ThreadImage : public DoublyLinkedListLinkImpl<ThreadImage> {
22public:
23								ThreadImage(Image* image,
24									ImageProfileResult* result);
25								~ThreadImage();
26
27			Image*				GetImage() const	{ return fImage; }
28			ImageProfileResult*	Result() const		{ return fResult; }
29
30private:
31			Image*				fImage;
32			ImageProfileResult*	fResult;
33};
34
35
36class Thread : public ProfiledEntity, public DoublyLinkedListLinkImpl<Thread>,
37	private ImageProfileResultContainer {
38public:
39								Thread(thread_id threadID, const char* name,
40									Team* team);
41	virtual						~Thread();
42
43	inline	thread_id			ID() const;
44	inline	const char*			Name() const;
45	inline	addr_t*				Samples() const;
46	inline	Team*				GetTeam() const;
47
48	virtual	int32				EntityID() const;
49	virtual	const char*			EntityName() const;
50	virtual	const char*			EntityType() const;
51
52	inline	ProfileResult*		GetProfileResult() const;
53			void				SetProfileResult(ProfileResult* result);
54
55			void				UpdateInfo(const char* name);
56
57			void				SetSampleArea(area_id area, addr_t* samples);
58			void				SetInterval(bigtime_t interval);
59
60			void				SetLazyImages(bool lazy);
61
62			status_t			AddImage(Image* image);
63			void				RemoveImage(Image* image);
64
65			void				AddSamples(int32 count, int32 dropped,
66									int32 stackDepth, bool variableStackDepth,
67									int32 event);
68			void				AddSamples(addr_t* samples, int32 sampleCount);
69			void				PrintResults();
70
71private:
72	typedef DoublyLinkedList<ThreadImage>	ImageList;
73
74private:
75	// ImageProfileResultContainer
76	virtual	int32				CountImages() const;
77	virtual	ImageProfileResult*	VisitImages(Visitor& visitor) const;
78	virtual	ImageProfileResult*	FindImage(addr_t address,
79									addr_t& _loadDelta) const;
80
81private:
82			void				_SynchronizeImages(int32 event);
83
84private:
85			thread_id			fID;
86			BString				fName;
87			::Team*				fTeam;
88			area_id				fSampleArea;
89			addr_t*				fSamples;
90			ProfileResult*		fProfileResult;
91			ImageList			fImages;
92			ImageList			fNewImages;
93			ImageList			fOldImages;
94			bool				fLazyImages;
95};
96
97
98thread_id
99Thread::ID() const
100{
101	return fID;
102}
103
104
105const char*
106Thread::Name() const
107{
108	return fName.String();
109}
110
111
112addr_t*
113Thread::Samples() const
114{
115	return fSamples;
116}
117
118
119Team*
120Thread::GetTeam() const
121{
122	return fTeam;
123}
124
125
126ProfileResult*
127Thread::GetProfileResult() const
128{
129	return fProfileResult;
130}
131
132
133#endif	// THREAD_H
134