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  */
  28 
  29 #ifndef _SYS_THREAD_H
  30 #define _SYS_THREAD_H
  31 
  32 #include <sys/types.h>
  33 #include <sys/t_lock.h>
  34 #include <sys/klwp.h>
  35 #include <sys/signal.h>  /* expected by including code */
  36 
  37 #ifdef  __cplusplus
  38 extern "C" {
  39 #endif
  40 
  41 /*
  42  * The thread object, its states, and the methods by which it
  43  * is accessed.
  44  */
  45 
  46 /*
  47  * Values that t_state may assume. Note that t_state cannot have more
  48  * than one of these flags set at a time.
  49  */
  50 #define TS_FREE         0x00    /* Thread at loose ends */
  51 #define TS_SLEEP        0x01    /* Awaiting an event */
  52 #define TS_RUN          0x02    /* Runnable, but not yet on a processor */
  53 #define TS_ONPROC       0x04    /* Thread is being run on a processor */
  54 #define TS_ZOMB         0x08    /* Thread has died but hasn't been reaped */
  55 #define TS_STOPPED      0x10    /* Stopped, initial state */
  56 #define TS_WAIT         0x20    /* Waiting to become runnable */
  57 
  58 /* ctxop_t */
  59 
  60 /* afd_t needed by sys/file.h via sys/t_lock.h */
  61 typedef struct _afd_not_used afd_t;
  62 
  63 struct turnstile;
  64 struct panic_trap_info;
  65 struct upimutex;
  66 struct kproject;
  67 struct on_trap_data;
  68 struct waitq;
  69 struct _kcpc_ctx;
  70 struct _kcpc_set;
  71 
  72 /* Definition for kernel thread identifier type */
  73 typedef uint64_t kt_did_t;
  74 
  75 struct _kthread;
  76 typedef struct _kthread *kthread_id_t;
  77 
  78 typedef struct _kthread kthread_t;
  79 
  80 extern  kthread_t       *_curthread(void);      /* returns thread pointer */
  81 #define curthread       (_curthread())          /* current thread pointer */
  82 
  83 #define _KTHREAD_INVALID        ((void *)(uintptr_t)-1)
  84 
  85 
  86 struct proc;
  87 extern struct proc      *_curproc(void);
  88 #define curproc         (_curproc())            /* current proc pointer */
  89 
  90 struct zone;
  91 extern struct zone      *_curzone(void);
  92 #define curzone         (_curzone())            /* current zone pointer */
  93 
  94 extern  kthread_t       *thread_create(
  95         caddr_t         stk,
  96         size_t          stksize,
  97         void            (*proc)(),
  98         void            *arg,
  99         size_t          len,
 100         struct proc     *pp,
 101         int             state,
 102         pri_t           pri);
 103 extern  void    thread_exit(void) __NORETURN;
 104 extern  void    thread_join(kt_did_t);
 105 
 106 extern kthread_t *zthread_create(caddr_t, size_t, void (*)(), void *, size_t,
 107     pri_t);
 108 extern void zthread_exit(void) __NORETURN;
 109 
 110 #ifdef  __cplusplus
 111 }
 112 #endif
 113 
 114 #endif /* _SYS_THREAD_H */