1b819cea2SGordon Ross /*
2b819cea2SGordon Ross  * CDDL HEADER START
3b819cea2SGordon Ross  *
4b819cea2SGordon Ross  * The contents of this file are subject to the terms of the
5b819cea2SGordon Ross  * Common Development and Distribution License (the "License").
6b819cea2SGordon Ross  * You may not use this file except in compliance with the License.
7b819cea2SGordon Ross  *
8b819cea2SGordon Ross  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9b819cea2SGordon Ross  * or http://www.opensolaris.org/os/licensing.
10b819cea2SGordon Ross  * See the License for the specific language governing permissions
11b819cea2SGordon Ross  * and limitations under the License.
12b819cea2SGordon Ross  *
13b819cea2SGordon Ross  * When distributing Covered Code, include this CDDL HEADER in each
14b819cea2SGordon Ross  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15b819cea2SGordon Ross  * If applicable, add the following below this CDDL HEADER, with the
16b819cea2SGordon Ross  * fields enclosed by brackets "[]" replaced with your own identifying
17b819cea2SGordon Ross  * information: Portions Copyright [yyyy] [name of copyright owner]
18b819cea2SGordon Ross  *
19b819cea2SGordon Ross  * CDDL HEADER END
20b819cea2SGordon Ross  */
21b819cea2SGordon Ross 
22b819cea2SGordon Ross /*
23b819cea2SGordon Ross  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24b819cea2SGordon Ross  * Use is subject to license terms.
25b819cea2SGordon Ross  *
26b819cea2SGordon Ross  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
27*ab618543SJohn Levon  * Copyright 2018 Joyent, Inc.
28b819cea2SGordon Ross  */
29b819cea2SGordon Ross 
30b819cea2SGordon Ross #ifndef	_SYS_THREAD_H
31b819cea2SGordon Ross #define	_SYS_THREAD_H
32b819cea2SGordon Ross 
33b819cea2SGordon Ross #include <sys/types.h>
34b819cea2SGordon Ross #include <sys/t_lock.h>
35b819cea2SGordon Ross #include <sys/klwp.h>
36b819cea2SGordon Ross #include <sys/signal.h>  /* expected by including code */
37b819cea2SGordon Ross 
38b819cea2SGordon Ross #ifdef	__cplusplus
39b819cea2SGordon Ross extern "C" {
40b819cea2SGordon Ross #endif
41b819cea2SGordon Ross 
42b819cea2SGordon Ross /*
43b819cea2SGordon Ross  * The thread object, its states, and the methods by which it
44b819cea2SGordon Ross  * is accessed.
45b819cea2SGordon Ross  */
46b819cea2SGordon Ross 
47b819cea2SGordon Ross /*
48b819cea2SGordon Ross  * Values that t_state may assume. Note that t_state cannot have more
49b819cea2SGordon Ross  * than one of these flags set at a time.
50b819cea2SGordon Ross  */
51b819cea2SGordon Ross #define	TS_FREE		0x00	/* Thread at loose ends */
52b819cea2SGordon Ross #define	TS_SLEEP	0x01	/* Awaiting an event */
53b819cea2SGordon Ross #define	TS_RUN		0x02	/* Runnable, but not yet on a processor */
54b819cea2SGordon Ross #define	TS_ONPROC	0x04	/* Thread is being run on a processor */
55b819cea2SGordon Ross #define	TS_ZOMB		0x08	/* Thread has died but hasn't been reaped */
56b819cea2SGordon Ross #define	TS_STOPPED	0x10	/* Stopped, initial state */
57b819cea2SGordon Ross #define	TS_WAIT		0x20	/* Waiting to become runnable */
58b819cea2SGordon Ross 
59b819cea2SGordon Ross /* ctxop_t */
60b819cea2SGordon Ross 
61b819cea2SGordon Ross /* afd_t needed by sys/file.h via sys/t_lock.h */
62b819cea2SGordon Ross typedef struct _afd_not_used afd_t;
63b819cea2SGordon Ross 
64b819cea2SGordon Ross struct turnstile;
65b819cea2SGordon Ross struct panic_trap_info;
66b819cea2SGordon Ross struct upimutex;
67b819cea2SGordon Ross struct kproject;
68b819cea2SGordon Ross struct on_trap_data;
69b819cea2SGordon Ross struct waitq;
70b819cea2SGordon Ross struct _kcpc_ctx;
71b819cea2SGordon Ross struct _kcpc_set;
72b819cea2SGordon Ross 
73b819cea2SGordon Ross /* Definition for kernel thread identifier type */
74b819cea2SGordon Ross typedef uint64_t kt_did_t;
75b819cea2SGordon Ross 
76b819cea2SGordon Ross struct _kthread;
77b819cea2SGordon Ross typedef struct _kthread	*kthread_id_t;
78b819cea2SGordon Ross 
79b819cea2SGordon Ross typedef struct _kthread kthread_t;
80b819cea2SGordon Ross 
81b819cea2SGordon Ross extern	kthread_t	*_curthread(void);	/* returns thread pointer */
82b819cea2SGordon Ross #define	curthread	(_curthread())		/* current thread pointer */
83b819cea2SGordon Ross 
84b819cea2SGordon Ross #define	_KTHREAD_INVALID	((void *)(uintptr_t)-1)
85b819cea2SGordon Ross 
86*ab618543SJohn Levon #define	THREAD_NAME_MAX	(32)
87b819cea2SGordon Ross 
88b819cea2SGordon Ross struct proc;
89b819cea2SGordon Ross extern struct proc	*_curproc(void);
90b819cea2SGordon Ross #define	curproc		(_curproc())		/* current proc pointer */
91b819cea2SGordon Ross 
92b819cea2SGordon Ross struct zone;
93b819cea2SGordon Ross extern struct zone	*_curzone(void);
94b819cea2SGordon Ross #define	curzone		(_curzone())		/* current zone pointer */
95b819cea2SGordon Ross 
96b819cea2SGordon Ross extern	kthread_t	*thread_create(
97b819cea2SGordon Ross 	caddr_t		stk,
98b819cea2SGordon Ross 	size_t		stksize,
99b819cea2SGordon Ross 	void		(*proc)(),
100b819cea2SGordon Ross 	void		*arg,
101b819cea2SGordon Ross 	size_t		len,
102b819cea2SGordon Ross 	struct proc	*pp,
103b819cea2SGordon Ross 	int		state,
104b819cea2SGordon Ross 	pri_t		pri);
105b819cea2SGordon Ross extern	void	thread_exit(void) __NORETURN;
106b819cea2SGordon Ross extern	void	thread_join(kt_did_t);
107b819cea2SGordon Ross 
108b819cea2SGordon Ross extern kthread_t *zthread_create(caddr_t, size_t, void (*)(), void *, size_t,
109b819cea2SGordon Ross     pri_t);
110b819cea2SGordon Ross extern void zthread_exit(void) __NORETURN;
111b819cea2SGordon Ross 
112b819cea2SGordon Ross #ifdef	__cplusplus
113b819cea2SGordon Ross }
114b819cea2SGordon Ross #endif
115b819cea2SGordon Ross 
116b819cea2SGordon Ross #endif /* _SYS_THREAD_H */