197dda329SAxel Dörfler/*
2467fe4caSIngo Weinhold * Copyright 2004-2016, Haiku, Inc.
32080a7c0SAxel Dörfler * Distributed under the terms of the MIT License.
42080a7c0SAxel Dörfler *
52080a7c0SAxel Dörfler * Thread definition and structures
62080a7c0SAxel Dörfler */
7420a6221SAxel Dörfler#ifndef _KERNEL_THREAD_TYPES_H
8420a6221SAxel Dörfler#define _KERNEL_THREAD_TYPES_H
9420a6221SAxel Dörfler
1068d9d880SAxel Dörfler
1134b3b26bSIngo Weinhold#ifndef _ASSEMBLER
12564cba31SAxel Dörfler
1324df6592SIngo Weinhold#include <pthread.h>
142d8d1cdbSIngo Weinhold
155662ae45SIngo Weinhold#include <arch/thread_types.h>
165662ae45SIngo Weinhold#include <condition_variable.h>
1724df6592SIngo Weinhold#include <heap.h>
1824df6592SIngo Weinhold#include <ksignal.h>
192d8d1cdbSIngo Weinhold#include <lock.h>
205662ae45SIngo Weinhold#include <smp.h>
216b202f4eSIngo Weinhold#include <thread_defs.h>
22420a6221SAxel Dörfler#include <timer.h>
2324df6592SIngo Weinhold#include <UserTimer.h>
24032fea39SIngo Weinhold#include <user_debugger.h>
25eeecbf6fSIngo Weinhold#include <util/DoublyLinkedList.h>
2624df6592SIngo Weinhold#include <util/KernelReferenceable.h>
27c7a03dadSAxel Dörfler#include <util/list.h>
28420a6221SAxel Dörfler
29420a6221SAxel Dörfler
30420a6221SAxel Dörflerenum additional_thread_state {
31420a6221SAxel Dörfler	THREAD_STATE_FREE_ON_RESCHED = 7, // free the thread structure upon reschedule
32420a6221SAxel Dörfler//	THREAD_STATE_BIRTH	// thread is being created
33420a6221SAxel Dörfler};
34420a6221SAxel Dörfler
372c1e463cSAxel Dörfler
38420a6221SAxel Dörflerenum team_state {
3924df6592SIngo Weinhold	TEAM_STATE_NORMAL,		// normal state
4024df6592SIngo Weinhold	TEAM_STATE_BIRTH,		// being constructed
4124df6592SIngo Weinhold	TEAM_STATE_SHUTDOWN,	// still lives, but is going down
4224df6592SIngo Weinhold	TEAM_STATE_DEATH		// only the Team object still exists, threads are
4324df6592SIngo Weinhold							// gone
44420a6221SAxel Dörfler};
45420a6221SAxel Dörfler
46562e2f20SIngo Weinhold#define	TEAM_FLAG_EXEC_DONE	0x01
47467fe4caSIngo Weinhold	// team has executed exec*()
48467fe4caSIngo Weinhold#define	TEAM_FLAG_DUMP_CORE	0x02
49467fe4caSIngo Weinhold	// a core dump is in progress
50562e2f20SIngo Weinhold
5124bcf559SIngo Weinholdtypedef enum job_control_state {
5224bcf559SIngo Weinhold	JOB_CONTROL_STATE_NONE,
5324bcf559SIngo Weinhold	JOB_CONTROL_STATE_STOPPED,
5524bcf559SIngo Weinhold	JOB_CONTROL_STATE_DEAD
5624bcf559SIngo Weinhold} job_control_state;
5724bcf559SIngo Weinhold
582c1e463cSAxel Dörfler
594535495dSIngo Weinholdstruct cpu_ent;
605142c2acSIngo Weinholdstruct image;					// defined in image.c
615ecc4b37SIngo Weinholdstruct io_context;
625142c2acSIngo Weinholdstruct realtime_sem_context;	// defined in realtime_sem.cpp
63636bfc08SIngo Weinholdstruct select_info;
64d648afb8SIngo Weinholdstruct user_thread;				// defined in libroot/user_thread.h
654535495dSIngo Weinholdstruct VMAddressSpace;
666ae7f687SSalvatore Benedettostruct xsi_sem_context;			// defined in xsi_semaphore.cpp
67420a6221SAxel Dörfler
68d287274dSPawel Dziepaknamespace Scheduler {
69d287274dSPawel Dziepak	struct ThreadData;
70d287274dSPawel Dziepak}
71d287274dSPawel Dziepak
724535495dSIngo Weinholdnamespace BKernel {
734535495dSIngo Weinhold	struct Team;
744535495dSIngo Weinhold	struct Thread;
7524df6592SIngo Weinhold	struct ProcessGroup;
764535495dSIngo Weinhold}
774535495dSIngo Weinhold
784535495dSIngo Weinhold
7924df6592SIngo Weinholdstruct thread_death_entry {
802500c27bSAxel Dörfler	struct list_link	link;
812500c27bSAxel Dörfler	thread_id			thread;
822500c27bSAxel Dörfler	status_t			status;
8307265ad7SAxel Dörfler};
8407265ad7SAxel Dörfler
850dd3a50bSIngo Weinholdstruct team_loading_info {
8613beda00SMichael Lotz	ConditionVariable	condition;
872e278745SAxel Dörfler	status_t			result;		// the result of the loading
880dd3a50bSIngo Weinhold};
890dd3a50bSIngo Weinhold
9099c566f6SAxel Dörflerstruct team_watcher {
9199c566f6SAxel Dörfler	struct list_link	link;
9299c566f6SAxel Dörfler	void				(*hook)(team_id team, void *data);
9399c566f6SAxel Dörfler	void				*data;
9499c566f6SAxel Dörfler};
9599c566f6SAxel Dörfler
965662ae45SIngo Weinhold
9707265ad7SAxel Dörfler#define MAX_DEAD_CHILDREN	32
9892ab20b3SIngo Weinhold	// this is a soft limit for the number of child death entries in a team
9992ab20b3SIngo Weinhold#define MAX_DEAD_THREADS	32
10092ab20b3SIngo Weinhold	// this is a soft limit for the number of thread death entries in a team
10107265ad7SAxel Dörfler
10224bcf559SIngo Weinhold
10324bcf559SIngo Weinholdstruct job_control_entry : DoublyLinkedListLinkImpl<job_control_entry> {
10424bcf559SIngo Weinhold	job_control_state	state;		// current team job control state
10524bcf559SIngo Weinhold	thread_id			thread;		// main thread ID == team ID
10624df6592SIngo Weinhold	uint16				signal;		// signal causing the current state
1074a7f236bSIngo Weinhold	bool				has_group_ref;
10824df6592SIngo Weinhold	uid_t				signaling_user;
10924bcf559SIngo Weinhold
11024bcf559SIngo Weinhold	// valid while state != JOB_CONTROL_STATE_DEAD
1114535495dSIngo Weinhold	BKernel::Team*		team;
11224bcf559SIngo Weinhold
11324bcf559SIngo Weinhold	// valid when state == JOB_CONTROL_STATE_DEAD
11424bcf559SIngo Weinhold	pid_t				group_id;
11524bcf559SIngo Weinhold	status_t			status;
11624df6592SIngo Weinhold	uint16				reason;		// reason for the team's demise, one of the
11724df6592SIngo Weinhold									// CLD_* values defined in <signal.h>
118a295d3f4SJérôme Duval	bigtime_t			user_time;
119a295d3f4SJérôme Duval	bigtime_t			kernel_time;
1204a7f236bSIngo Weinhold
1214a7f236bSIngo Weinhold	job_control_entry();
1224a7f236bSIngo Weinhold	~job_control_entry();
1234a7f236bSIngo Weinhold
1244a7f236bSIngo Weinhold	void InitDeadState();
1254a7f236bSIngo Weinhold
1264a7f236bSIngo Weinhold	job_control_entry& operator=(const job_control_entry& other);
12724bcf559SIngo Weinhold};
12824bcf559SIngo Weinhold
12924bcf559SIngo Weinholdtypedef DoublyLinkedList<job_control_entry> JobControlEntryList;
13024bcf559SIngo Weinhold
13124bcf559SIngo Weinholdstruct team_job_control_children {
13266aac81eSIngo Weinhold	JobControlEntryList		entries;
13324bcf559SIngo Weinhold};
134ff895459SIngo Weinhold
13524bcf559SIngo Weinholdstruct team_dead_children : team_job_control_children {
1366cef245eSIngo Weinhold	ConditionVariable	condition_variable;
1376cef245eSIngo Weinhold	uint32				count;
1386cef245eSIngo Weinhold	bigtime_t			kernel_time;
1396cef245eSIngo Weinhold	bigtime_t			user_time;
140ff895459SIngo Weinhold};
141ff895459SIngo Weinhold
14224bcf559SIngo Weinhold
1435662ae45SIngo Weinholdstruct team_death_entry {
1445662ae45SIngo Weinhold	int32				remaining_threads;
1455662ae45SIngo Weinhold	ConditionVariable	condition;
1465662ae45SIngo Weinhold};
1475662ae45SIngo Weinhold
1485662ae45SIngo Weinhold
149d648afb8SIngo Weinholdstruct free_user_thread {
150d648afb8SIngo Weinhold	struct free_user_thread*	next;
151d648afb8SIngo Weinhold	struct user_thread*			thread;
152d648afb8SIngo Weinhold};
153d648afb8SIngo Weinhold
1540296b82aSRene Gollent
1552d8d1cdbSIngo Weinholdclass AssociatedDataOwner;
1562d8d1cdbSIngo Weinhold
15788e38c17SIngo Weinholdclass AssociatedData : public BReferenceable,
1582d8d1cdbSIngo Weinhold	public DoublyLinkedListLinkImpl<AssociatedData> {
1592d8d1cdbSIngo Weinholdpublic:
1602d8d1cdbSIngo Weinhold								AssociatedData();
1612d8d1cdbSIngo Weinhold	virtual						~AssociatedData();
1622d8d1cdbSIngo Weinhold
1632d8d1cdbSIngo Weinhold			AssociatedDataOwner* Owner() const
1642d8d1cdbSIngo Weinhold									{ return fOwner; }
1652d8d1cdbSIngo Weinhold			void				SetOwner(AssociatedDataOwner* owner)
1662d8d1cdbSIngo Weinhold									{ fOwner = owner; }
1672d8d1cdbSIngo Weinhold
1682d8d1cdbSIngo Weinhold	virtual	void				OwnerDeleted(AssociatedDataOwner* owner);
1692d8d1cdbSIngo Weinhold
1702d8d1cdbSIngo Weinholdprivate:
1712d8d1cdbSIngo Weinhold			AssociatedDataOwner* fOwner;
1722d8d1cdbSIngo Weinhold};
1732d8d1cdbSIngo Weinhold
1742d8d1cdbSIngo Weinhold
1752d8d1cdbSIngo Weinholdclass AssociatedDataOwner {
1762d8d1cdbSIngo Weinholdpublic:
1772d8d1cdbSIngo Weinhold								AssociatedDataOwner();
1782d8d1cdbSIngo Weinhold								~AssociatedDataOwner();
1792d8d1cdbSIngo Weinhold
1802d8d1cdbSIngo Weinhold			bool				AddData(AssociatedData* data);
1812d8d1cdbSIngo Weinhold			bool				RemoveData(AssociatedData* data);
1822d8d1cdbSIngo Weinhold
1832d8d1cdbSIngo Weinhold			void				PrepareForDeletion();
1842d8d1cdbSIngo Weinhold
1852d8d1cdbSIngo Weinholdprivate:
1862d8d1cdbSIngo Weinhold			typedef DoublyLinkedList<AssociatedData> DataList;
1872d8d1cdbSIngo Weinhold
1882d8d1cdbSIngo Weinholdprivate:
1892d8d1cdbSIngo Weinhold
1902d8d1cdbSIngo Weinhold			mutex				fLock;
1912d8d1cdbSIngo Weinhold			DataList			fList;
1922d8d1cdbSIngo Weinhold};
1932d8d1cdbSIngo Weinhold
1942d8d1cdbSIngo Weinhold
1954535495dSIngo Weinholdtypedef int32 (*thread_entry_func)(thread_func, void *);
1964535495dSIngo Weinhold
1974535495dSIngo Weinhold
1984535495dSIngo Weinholdnamespace BKernel {
1994535495dSIngo Weinhold
20024df6592SIngo Weinhold
20124df6592SIngo Weinholdtemplate<typename IDType>
20224df6592SIngo Weinholdstruct TeamThreadIteratorEntry
20324df6592SIngo Weinhold	: DoublyLinkedListLinkImpl<TeamThreadIteratorEntry<IDType> > {
20424df6592SIngo Weinhold	typedef IDType	id_type;
20524df6592SIngo Weinhold	typedef TeamThreadIteratorEntry<id_type> iterator_type;
20624df6592SIngo Weinhold
20724df6592SIngo Weinhold	id_type	id;			// -1 for iterator entries, >= 0 for actual elements
20824df6592SIngo Weinhold	bool	visible;	// the entry is publicly visible
20924df6592SIngo Weinhold};
21024df6592SIngo Weinhold
21124df6592SIngo Weinhold
21224df6592SIngo Weinholdstruct Team : TeamThreadIteratorEntry<team_id>, KernelReferenceable,
21324df6592SIngo Weinhold		AssociatedDataOwner {
21424df6592SIngo Weinhold	DoublyLinkedListLink<Team>	global_list_link;
21524df6592SIngo Weinhold	Team			*hash_next;		// next in hash
21624df6592SIngo Weinhold	Team			*siblings_next;	// next in parent's list; protected by
21724df6592SIngo Weinhold									// parent's fLock
21824df6592SIngo Weinhold	Team			*parent;		// write-protected by both parent (if any)
21924df6592SIngo Weinhold									// and this team's fLock
22024df6592SIngo Weinhold	Team			*children;		// protected by this team's fLock;
22124df6592SIngo Weinhold									// adding/removing a child also requires the
22224df6592SIngo Weinhold									// child's fLock
22324df6592SIngo Weinhold	Team			*group_next;	// protected by the group's lock
22424df6592SIngo Weinhold
22524df6592SIngo Weinhold	int64			serial_number;	// immutable after adding team to hash
22624df6592SIngo Weinhold
22724df6592SIngo Weinhold	// process group info -- write-protected by both the group's lock, the
22824df6592SIngo Weinhold	// team's lock, and the team's parent's lock
22907265ad7SAxel Dörfler	pid_t			group_id;
23007265ad7SAxel Dörfler	pid_t			session_id;
23124df6592SIngo Weinhold	ProcessGroup	*group;
23224df6592SIngo Weinhold
2332b6a3688SAxel Dörfler	int				num_threads;	// number of threads in this team
2342b6a3688SAxel Dörfler	int				state;			// current team state, see above
235562e2f20SIngo Weinhold	int32			flags;
2365ecc4b37SIngo Weinhold	struct io_context *io_context;
2375142c2acSIngo Weinhold	struct realtime_sem_context	*realtime_sem_context;
2386ae7f687SSalvatore Benedetto	struct xsi_sem_context *xsi_sem_context;
23924df6592SIngo Weinhold	struct team_death_entry *death_entry;	// protected by fLock
24092ab20b3SIngo Weinhold	struct list		dead_threads;
24192ab20b3SIngo Weinhold	int				dead_threads_count;
24224bcf559SIngo Weinhold
24324df6592SIngo Weinhold	// protected by the team's fLock
2444535495dSIngo Weinhold	team_dead_children dead_children;
2454535495dSIngo Weinhold	team_job_control_children stopped_children;
2464535495dSIngo Weinhold	team_job_control_children continued_children;
24724df6592SIngo Weinhold
24824df6592SIngo Weinhold	// protected by the parent team's fLock
24924bcf559SIngo Weinhold	struct job_control_entry* job_control_entry;
25024bcf559SIngo Weinhold
2514535495dSIngo Weinhold	VMAddressSpace	*address_space;
25203fb2d88SPawel Dziepak	Thread			*main_thread;	// protected by fLock, immutable
25324df6592SIngo Weinhold									// after first set
25403fb2d88SPawel Dziepak	Thread			*thread_list;	// protected by fLock, signal_lock and
25503fb2d88SPawel Dziepak									// gThreadCreationLock
25624df6592SIngo Weinhold	struct team_loading_info *loading_info;	// protected by fLock
25724df6592SIngo Weinhold	struct list		image_list;		// protected by sImageMutex
25899c566f6SAxel Dörfler	struct list		watcher_list;
25924df6592SIngo Weinhold	struct list		sem_list;		// protected by sSemsSpinlock
26024df6592SIngo Weinhold	struct list		port_list;		// protected by sPortsLock
261420a6221SAxel Dörfler	struct arch_team arch_info;
2622080a7c0SAxel Dörfler
263d648afb8SIngo Weinhold	addr_t			user_data;
264d648afb8SIngo Weinhold	area_id			user_data_area;
265d648afb8SIngo Weinhold	size_t			user_data_size;
266d648afb8SIngo Weinhold	size_t			used_user_data;
267d648afb8SIngo Weinhold	struct free_user_thread* free_user_threads;
268d648afb8SIngo Weinhold
269e85e399fSPawel Dziepak	void*			commpage_address;
270e85e399fSPawel Dziepak
271032fea39SIngo Weinhold	struct team_debug_info debug_info;
272032fea39SIngo Weinhold
27372addc62SPawel Dziepak	// protected by time_lock
2742080a7c0SAxel Dörfler	bigtime_t		dead_threads_kernel_time;
2752080a7c0SAxel Dörfler	bigtime_t		dead_threads_user_time;
27624df6592SIngo Weinhold	bigtime_t		cpu_clock_offset;
27772addc62SPawel Dziepak	spinlock		time_lock;
2784eb35609SIngo Weinhold
27903fb2d88SPawel Dziepak	// user group information; protected by fLock
2804eb35609SIngo Weinhold	uid_t			saved_set_uid;
2814eb35609SIngo Weinhold	uid_t			real_uid;
2824eb35609SIngo Weinhold	uid_t			effective_uid;
2834eb35609SIngo Weinhold	gid_t			saved_set_gid;
2844eb35609SIngo Weinhold	gid_t			real_gid;
2854eb35609SIngo Weinhold	gid_t			effective_gid;
286290946ceSIngo Weinhold	gid_t*			supplementary_groups;
287290946ceSIngo Weinhold	int				supplementary_group_count;
28824df6592SIngo Weinhold
28924df6592SIngo Weinhold	// Exit status information. Set when the first terminal event occurs,
29024df6592SIngo Weinhold	// immutable afterwards. Protected by fLock.
29124df6592SIngo Weinhold	struct {
29224df6592SIngo Weinhold		uint16		reason;			// reason for the team's demise, one of the
29324df6592SIngo Weinhold									// CLD_* values defined in <signal.h>
29424df6592SIngo Weinhold		uint16		signal;			// signal killing the team
29524df6592SIngo Weinhold		uid_t		signaling_user;	// real UID of the signal sender
29624df6592SIngo Weinhold		status_t	status;			// exit status, if normal team exit
29724df6592SIngo Weinhold		bool		initialized;	// true when the state has been initialized
29824df6592SIngo Weinhold	} exit;
29924df6592SIngo Weinhold
300aa4aca02SPawel Dziepak	spinlock		signal_lock;
301aa4aca02SPawel Dziepak
30224df6592SIngo Weinholdpublic:
30324df6592SIngo Weinhold								~Team();
30424df6592SIngo Weinhold
30524df6592SIngo Weinhold	static	Team*				Create(team_id id, const char* name,
30624df6592SIngo Weinhold									bool kernel);
30724df6592SIngo Weinhold	static	Team*				Get(team_id id);
30824df6592SIngo Weinhold	static	Team*				GetAndLock(team_id id);
30924df6592SIngo Weinhold
31024df6592SIngo Weinhold			bool				Lock()
31124df6592SIngo Weinhold									{ mutex_lock(&fLock); return true; }
31224df6592SIngo Weinhold			bool				TryLock()
31324df6592SIngo Weinhold									{ return mutex_trylock(&fLock) == B_OK; }
31424df6592SIngo Weinhold			void				Unlock()
31524df6592SIngo Weinhold									{ mutex_unlock(&fLock); }
31624df6592SIngo Weinhold
31724df6592SIngo Weinhold			void				UnlockAndReleaseReference()
31824df6592SIngo Weinhold									{ Unlock(); ReleaseReference(); }
31924df6592SIngo Weinhold
32024df6592SIngo Weinhold			void				LockTeamAndParent(bool dontLockParentIfKernel);
32124df6592SIngo Weinhold			void				UnlockTeamAndParent();
32224df6592SIngo Weinhold			void				LockTeamAndProcessGroup();
32324df6592SIngo Weinhold			void				UnlockTeamAndProcessGroup();
32424df6592SIngo Weinhold			void				LockTeamParentAndProcessGroup();
32524df6592SIngo Weinhold			void				UnlockTeamParentAndProcessGroup();
32624df6592SIngo Weinhold			void				LockProcessGroup()
32724df6592SIngo Weinhold									{ LockTeamAndProcessGroup(); Unlock(); }
32824df6592SIngo Weinhold
32924df6592SIngo Weinhold			const char*			Name() const	{ return fName; }
33024df6592SIngo Weinhold			void				SetName(const char* name);
33124df6592SIngo Weinhold
33224df6592SIngo Weinhold			const char*			Args() const	{ return fArgs; }
33324df6592SIngo Weinhold			void				SetArgs(const char* args);
33424df6592SIngo Weinhold			void				SetArgs(const char* path,
33524df6592SIngo Weinhold									const char* const* otherArgs,
33624df6592SIngo Weinhold									int otherArgCount);
33724df6592SIngo Weinhold
33824df6592SIngo Weinhold			BKernel::QueuedSignalsCounter* QueuedSignalsCounter() const
33924df6592SIngo Weinhold									{ return fQueuedSignalsCounter; }
34024df6592SIngo Weinhold			sigset_t			PendingSignals() const
34124df6592SIngo Weinhold									{ return fPendingSignals.AllSignals(); }
34224df6592SIngo Weinhold
34324df6592SIngo Weinhold			void				AddPendingSignal(int signal)
34424df6592SIngo Weinhold									{ fPendingSignals.AddSignal(signal); }
34524df6592SIngo Weinhold			void				AddPendingSignal(Signal* signal)
34624df6592SIngo Weinhold									{ fPendingSignals.AddSignal(signal); }
34724df6592SIngo Weinhold			void				RemovePendingSignal(int signal)
34824df6592SIngo Weinhold									{ fPendingSignals.RemoveSignal(signal); }
34924df6592SIngo Weinhold			void				RemovePendingSignal(Signal* signal)
35024df6592SIngo Weinhold									{ fPendingSignals.RemoveSignal(signal); }
35124df6592SIngo Weinhold			void				RemovePendingSignals(sigset_t mask)
35224df6592SIngo Weinhold									{ fPendingSignals.RemoveSignals(mask); }
35324df6592SIngo Weinhold			void				ResetSignalsOnExec();
35424df6592SIngo Weinhold
35524df6592SIngo Weinhold	inline	int32				HighestPendingSignalPriority(
35624df6592SIngo Weinhold									sigset_t nonBlocked) const;
35724df6592SIngo Weinhold	inline	Signal*				DequeuePendingSignal(sigset_t nonBlocked,
35824df6592SIngo Weinhold									Signal& buffer);
35924df6592SIngo Weinhold
36024df6592SIngo Weinhold			struct sigaction&	SignalActionFor(int32 signal)
36124df6592SIngo Weinhold									{ return fSignalActions[signal - 1]; }
36224df6592SIngo Weinhold			void				InheritSignalActions(Team* parent);
36324df6592SIngo Weinhold
36424df6592SIngo Weinhold			// user timers -- protected by fLock
36524df6592SIngo Weinhold			UserTimer*			UserTimerFor(int32 id) const
36624df6592SIngo Weinhold									{ return fUserTimers.TimerFor(id); }
36724df6592SIngo Weinhold			status_t			AddUserTimer(UserTimer* timer);
36824df6592SIngo Weinhold			void				RemoveUserTimer(UserTimer* timer);
36924df6592SIngo Weinhold			void				DeleteUserTimers(bool userDefinedOnly);
37024df6592SIngo Weinhold
37124df6592SIngo Weinhold			bool				CheckAddUserDefinedTimer();
37224df6592SIngo Weinhold			void				UserDefinedTimersRemoved(int32 count);
37324df6592SIngo Weinhold
37424df6592SIngo Weinhold			void				UserTimerActivated(TeamTimeUserTimer* timer)
37524df6592SIngo Weinhold									{ fCPUTimeUserTimers.Add(timer); }
37624df6592SIngo Weinhold			void				UserTimerActivated(TeamUserTimeUserTimer* timer)
37724df6592SIngo Weinhold									{ fUserTimeUserTimers.Add(timer); }
37824df6592SIngo Weinhold			void				UserTimerDeactivated(TeamTimeUserTimer* timer)
37924df6592SIngo Weinhold									{ fCPUTimeUserTimers.Remove(timer); }
38024df6592SIngo Weinhold			void				UserTimerDeactivated(
38124df6592SIngo Weinhold									TeamUserTimeUserTimer* timer)
38224df6592SIngo Weinhold									{ fUserTimeUserTimers.Remove(timer); }
38324df6592SIngo Weinhold			void				DeactivateCPUTimeUserTimers();
38424df6592SIngo Weinhold									// both total and user CPU timers
38524df6592SIngo Weinhold			bool				HasActiveCPUTimeUserTimers() const
38624df6592SIngo Weinhold									{ return !fCPUTimeUserTimers.IsEmpty(); }
38724df6592SIngo Weinhold			bool				HasActiveUserTimeUserTimers() const
38824df6592SIngo Weinhold									{ return !fUserTimeUserTimers.IsEmpty(); }
38924df6592SIngo Weinhold			TeamTimeUserTimerList::ConstIterator
39024df6592SIngo Weinhold									CPUTimeUserTimerIterator() const
39124df6592SIngo Weinhold									{ return fCPUTimeUserTimers.GetIterator(); }
39224df6592SIngo Weinhold	inline	TeamUserTimeUserTimerList::ConstIterator
39324df6592SIngo Weinhold									UserTimeUserTimerIterator() const;
39424df6592SIngo Weinhold
39552d500e5SMichael Lotz			bigtime_t			CPUTime(bool ignoreCurrentRun,
39652d500e5SMichael Lotz									Thread* lockedThread = NULL) const;
39724df6592SIngo Weinhold			bigtime_t			UserCPUTime() const;
39824df6592SIngo Weinhold
399467fe4caSIngo Weinhold			ConditionVariable*	CoreDumpCondition() const
400467fe4caSIngo Weinhold									{ return fCoreDumpCondition; }
401467fe4caSIngo Weinhold			void				SetCoreDumpCondition(
402467fe4caSIngo Weinhold									ConditionVariable* condition)
403467fe4caSIngo Weinhold									{ fCoreDumpCondition = condition; }
40424df6592SIngo Weinholdprivate:
40524df6592SIngo Weinhold								Team(team_id id, bool kernel);
40624df6592SIngo Weinhold
40724df6592SIngo Weinholdprivate:
40824df6592SIngo Weinhold			mutex				fLock;
40924df6592SIngo Weinhold			char				fName[B_OS_NAME_LENGTH];
41024df6592SIngo Weinhold			char				fArgs[64];
41124df6592SIngo Weinhold									// contents for the team_info::args field
41224df6592SIngo Weinhold
41324df6592SIngo Weinhold			BKernel::QueuedSignalsCounter* fQueuedSignalsCounter;
41424df6592SIngo Weinhold			BKernel::PendingSignals	fPendingSignals;
415aa4aca02SPawel Dziepak									// protected by signal_lock
41624df6592SIngo Weinhold			struct sigaction 	fSignalActions[MAX_SIGNAL_NUMBER];
41724df6592SIngo Weinhold									// indexed signal - 1, protected by fLock
41824df6592SIngo Weinhold
41924df6592SIngo Weinhold			UserTimerList		fUserTimers;			// protected by fLock
42024df6592SIngo Weinhold			TeamTimeUserTimerList fCPUTimeUserTimers;
42124df6592SIngo Weinhold									// protected by scheduler lock
42224df6592SIngo Weinhold			TeamUserTimeUserTimerList fUserTimeUserTimers;
42373ad2473SPawel Dziepak			int32				fUserDefinedTimerCount;	// accessed atomically
424467fe4caSIngo Weinhold
425467fe4caSIngo Weinhold			ConditionVariable*	fCoreDumpCondition;
426467fe4caSIngo Weinhold									// protected by fLock
427420a6221SAxel Dörfler};
428420a6221SAxel Dörfler
4297da0a81cSAxel Dörfler
430d287274dSPawel Dziepakstruct Thread : TeamThreadIteratorEntry<thread_id>, KernelReferenceable {
43134b3b26bSIngo Weinhold	int32			flags;			// summary of events relevant in interrupt
43234b3b26bSIngo Weinhold									// handlers (signals pending, user debugging
43334b3b26bSIngo Weinhold									// enabled, etc.)
43424df6592SIngo Weinhold	int64			serial_number;	// immutable after adding thread to hash
43524df6592SIngo Weinhold	Thread			*hash_next;		// protected by thread hash lock
43624df6592SIngo Weinhold	Thread			*team_next;		// protected by team lock and fLock
43724df6592SIngo Weinhold	char			name[B_OS_NAME_LENGTH];	// protected by fLock
438b1673075SPawel Dziepak	bool			going_to_suspend;	// protected by scheduler lock
43924df6592SIngo Weinhold	int32			priority;		// protected by scheduler lock
44024df6592SIngo Weinhold	int32			io_priority;	// protected by fLock
44124df6592SIngo Weinhold	int32			state;			// protected by scheduler lock
44224df6592SIngo Weinhold	struct cpu_ent	*cpu;			// protected by scheduler lock