b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/*
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * CDDL HEADER START
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross *
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * The contents of this file are subject to the terms of the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Common Development and Distribution License (the "License").
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * You may not use this file except in compliance with the License.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross *
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * or http://www.opensolaris.org/os/licensing.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * See the License for the specific language governing permissions
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * and limitations under the License.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross *
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * When distributing Covered Code, include this CDDL HEADER in each
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * If applicable, add the following below this CDDL HEADER, with the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * fields enclosed by brackets "[]" replaced with your own identifying
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * information: Portions Copyright [yyyy] [name of copyright owner]
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross *
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * CDDL HEADER END
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/*
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Use is subject to license terms.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross *
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#ifndef _SYS_THREAD_H
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define _SYS_THREAD_H
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#include <sys/types.h>
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#include <sys/t_lock.h>
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#include <sys/klwp.h>
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#include <sys/signal.h> /* expected by including code */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#ifdef __cplusplus
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossextern "C" {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#endif
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/*
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * The thread object, its states, and the methods by which it
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * is accessed.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/*
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Values that t_state may assume. Note that t_state cannot have more
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * than one of these flags set at a time.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define TS_FREE 0x00 /* Thread at loose ends */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define TS_SLEEP 0x01 /* Awaiting an event */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define TS_RUN 0x02 /* Runnable, but not yet on a processor */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define TS_ONPROC 0x04 /* Thread is being run on a processor */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define TS_ZOMB 0x08 /* Thread has died but hasn't been reaped */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define TS_STOPPED 0x10 /* Stopped, initial state */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define TS_WAIT 0x20 /* Waiting to become runnable */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/* ctxop_t */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/* afd_t needed by sys/file.h via sys/t_lock.h */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosstypedef struct _afd_not_used afd_t;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct turnstile;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct panic_trap_info;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct upimutex;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct kproject;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct on_trap_data;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct waitq;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct _kcpc_ctx;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct _kcpc_set;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross/* Definition for kernel thread identifier type */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosstypedef uint64_t kt_did_t;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct _kthread;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosstypedef struct _kthread *kthread_id_t;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosstypedef struct _kthread kthread_t;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossextern kthread_t *_curthread(void); /* returns thread pointer */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define curthread (_curthread()) /* current thread pointer */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define _KTHREAD_INVALID ((void *)(uintptr_t)-1)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct proc;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossextern struct proc *_curproc(void);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define curproc (_curproc()) /* current proc pointer */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstruct zone;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossextern struct zone *_curzone(void);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#define curzone (_curzone()) /* current zone pointer */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossextern kthread_t *thread_create(
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross caddr_t stk,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross size_t stksize,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross void (*proc)(),
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross void *arg,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross size_t len,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross struct proc *pp,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross int state,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross pri_t pri);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossextern void thread_exit(void) __NORETURN;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossextern void thread_join(kt_did_t);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossextern kthread_t *zthread_create(caddr_t, size_t, void (*)(), void *, size_t,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross pri_t);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossextern void zthread_exit(void) __NORETURN;
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#ifdef __cplusplus
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross}
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#endif
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross#endif /* _SYS_THREAD_H */