Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2ebc8cbed82478baa600cf84aa3274796e579957 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*******************************************************************************
 * Copyright (c) 2012, 2013 Tilera Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     William R. Swanson (Tilera Corporation) - initial API and implementation
 *     Marc Khouzam (Ericsson)                 - Added knowledge about execution 
 *                                               state and os/gdb thread ids
 *     Marc Dumais (Ericsson) -  Bug 405390
 *     Marc Dumais (Ericsson) -  Bug 409965
 *******************************************************************************/

package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.model;


/** Represents single thread. */
public class VisualizerThread
	implements Comparable<VisualizerThread>, IVisualizerModelObject
{
	// --- members ---
	
	/** Current core this thread is on. */
	protected VisualizerCore m_core;
	
	/** Process ID (pid). */
	protected int m_pid;
	
	/** OS Thread ID (tid). */
	protected int m_tid;

	/** Thread ID as chosen by GDB. */
	protected int m_gdbtid;

	/** Thread execution state. */
	protected VisualizerExecutionState m_threadState;

	
	// --- constructors/destructors ---

	/** Constructor. */
	public VisualizerThread(VisualizerCore core, int pid, int tid, int gdbtid, VisualizerExecutionState state) {
		m_core = core;
		m_pid = pid;
		m_tid = tid;
		m_gdbtid = gdbtid;
		m_threadState = state;
	}
	
	/** Dispose method */
	public void dispose() {
		m_core = null;
	}
	
	
	// --- Object methods ---
	
	/** Equality comparison. */
	@Override
	public boolean equals(Object obj) {
		boolean result = false;
		if (obj instanceof VisualizerThread) {
			VisualizerThread v = (VisualizerThread) obj;
			result = (
				v.m_pid == m_pid &&
				v.m_tid == m_tid &&
				v.m_gdbtid == m_gdbtid
			);
		}
		return result;
	}

	@Override
	public int hashCode() {
		return m_pid ^ m_tid ^ m_gdbtid;
	}
	
	/** Returns string representation. */
	@Override
	public String toString() {
		StringBuffer output = new StringBuffer();
		output.append(m_core).append(",Proc:").append(m_pid) //$NON-NLS-1$
		      .append(",Thread:(").append(m_tid).append(",").append(m_gdbtid).append(")");  //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
		return output.toString();
	}

	
	// --- accessors ---
	
	/** Gets core. */
	public VisualizerCore getCore()	{
		return m_core;
	}
	
	public void setCore(VisualizerCore core) {
		m_core = core;
	}

	/** Returns true if this is the "process" thread, i.e.
	 *  its PID and OS TID are the same.
	 */
	public boolean isProcessThread()
	{
		return m_pid == m_tid;
	}
	
	/** Gets process id (pid). */
	public int getPID() {
		return m_pid;
	}
	
	/** Gets thread id (tid). */
	public int getTID()	{
		return m_tid;
	}
	
	/** Sets thread id (tid). */
	public void setTID(int tid)	{
		m_tid = tid;
	}

	/** Gets thread id (gdbtid). */
	@Override
	public int getID() {
		return getGDBTID();
	}

	/** Return core the thread is on */
	@Override
	public IVisualizerModelObject getParent() {
		return getCore();
	}
	
	/** Gets gdb thread id. */
	public int getGDBTID()	{
		return m_gdbtid;
	}

	/** Gets thread execution state. */
	public VisualizerExecutionState getState() {
		return m_threadState;
	}
	
	/** Sets thread execution state. */
	public void setState(VisualizerExecutionState state) {
		m_threadState = state;
	}
	
	
	// --- methods ---
	

	
	// --- Comparable implementation ---
	
	/** Compares this item to the specified item. */
	@Override
	public int compareTo(VisualizerThread o) {
		int result = 0;
		if (o != null) {
			if (m_pid < o.m_pid) {
				result = -1;
			}
			else if (m_pid > o.m_pid) {
				result = 1;
			}
			else if (getID() < o.getID()) {
				result = -1;
			}
			else if (getID() > o.getID()) {
				result = 1;
			}
		}
		return result;
	}
	
	/** IVisualizerModelObject version of compareTo() */
	@Override
	public int compareTo(IVisualizerModelObject o) {
		if (o != null) {
			if (o.getClass() == this.getClass()) {
				return compareTo((VisualizerThread)o);
			}
		}
		return 1;
	}
}

Back to the top