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