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