8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libfakekernel / common / thread.c
blobba16f3b8d5c418b15f6f4f674a7620a76eaec693
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
16 #include <sys/cmn_err.h>
17 #include <sys/thread.h>
18 #include <sys/zone.h>
20 #define _SYNCH_H /* keep out <synch.h> */
21 #include <thread.h>
24 * Get the current kthread_t pointer.
26 kthread_t *
27 _curthread(void)
29 thread_t tid;
31 tid = thr_self();
32 return ((kthread_t *)(uintptr_t)tid);
36 * Create a thread.
38 * thread_create() blocks for memory if necessary. It never fails.
40 /* ARGSUSED */
41 kthread_t *
42 thread_create(
43 caddr_t stk,
44 size_t stksize,
45 void (*func)(),
46 void *arg,
47 size_t len,
48 struct proc *pp,
49 int state,
50 pri_t pri)
52 void * (*thr_func)(void *);
53 thread_t newtid;
54 int thr_flags = 0;
55 int rc;
57 thr_flags = THR_BOUND;
59 switch (state) {
60 case TS_RUN:
61 case TS_ONPROC:
62 break;
63 case TS_STOPPED:
64 thr_flags |= THR_SUSPENDED;
65 break;
66 default:
67 cmn_err(CE_PANIC, "thread_create: invalid state");
68 break;
71 thr_func = (void *(*)(void *))func;
72 rc = thr_create(NULL, 0, thr_func, arg, thr_flags, &newtid);
73 if (rc != 0)
74 cmn_err(CE_PANIC, "thread_create failed, rc=%d", rc);
76 return ((void *)(uintptr_t)newtid);
79 void
80 thread_exit(void)
82 thr_exit(NULL);
85 void
86 thread_join(kt_did_t id)
88 thread_t thr_id;
90 thr_id = (thread_t)id;
91 (void) thr_join(thr_id, NULL, NULL);
94 void
95 tsignal(kthread_t *kt, int sig)
97 thread_t tid = (thread_t)(uintptr_t)kt;
99 (void) thr_kill(tid, sig);
103 /*ARGSUSED*/
104 kthread_t *
105 zthread_create(
106 caddr_t stk,
107 size_t stksize,
108 void (*func)(),
109 void *arg,
110 size_t len,
111 pri_t pri)
113 kthread_t *t;
115 t = thread_create(stk, stksize, func, arg, len, NULL, TS_RUN, pri);
117 return (t);
120 void
121 zthread_exit(void)
123 thread_exit();
124 /* NOTREACHED */