2 * Copyright (C) 2001 Julian Elischer <julian@freebsd.org>
3 * for the FreeBSD Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice(s), this list of conditions and the following disclaimer as
12 * the first lines of this file unmodified other than the possible
13 * addition of one or more copyright notices.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice(s), this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
36 #include <sys/ucontext.h>
38 #include <sys/signal.h>
41 * This file defines the structures needed for communication between
42 * the userland and the kernel when running a KSE-based threading system.
43 * The only programs that should see this file are the user thread
44 * scheduler (UTS) and the kernel.
48 typedef void kse_func_t(struct kse_mailbox *);
53 * This describes a user thread to the kernel scheduler.
55 struct kse_thr_mailbox {
56 ucontext_t tm_context; /* User and machine context */
57 unsigned int tm_flags; /* Thread flags */
58 struct kse_thr_mailbox *tm_next; /* Next thread in list */
59 void *tm_udata; /* For use by the UTS */
69 * Communication path between the UTS and the kernel scheduler specific to
73 int km_version; /* Mailbox version */
74 struct kse_thr_mailbox *km_curthread; /* Currently running thread */
75 struct kse_thr_mailbox *km_completed; /* Threads back from kernel */
76 sigset_t km_sigscaught; /* Caught signals */
77 uint32_t km_flags; /* KSE flags */
78 kse_func_t *km_func; /* UTS function */
79 stack_t km_stack; /* UTS context */
80 void *km_udata; /* For use by the UTS */
81 struct timespec km_timeofday; /* Time of day */
82 int km_quantum; /* Upcall quantum in msecs */
87 #define KSE_VERSION KSE_VER_0
89 /* These flags are kept in km_flags */
90 #define KMF_NOUPCALL 0x01
91 #define KMF_NOCOMPLETED 0x02
93 #define KMF_BOUND 0x08
94 #define KMF_WAITSIGEVENT 0x10
96 /* These flags are kept in tm_flags */
97 #define TMF_NOUPCALL 0x01
99 /* Commands for kse_thr_interrupt */
100 #define KSE_INTR_INTERRUPT 0x01
101 #define KSE_INTR_RESTART 0x02
102 #define KSE_INTR_SENDSIG 0x03
103 #define KSE_INTR_SIGEXIT 0x04
106 int kse_create(struct kse_mailbox *, int);
108 int kse_release(struct timespec *);
109 int kse_thr_interrupt(struct kse_thr_mailbox *, int, long);
110 int kse_wakeup(struct kse_mailbox *);
111 int kse_switchin(mcontext_t *, long, long *);
112 #endif /* !_KERNEL */
114 #endif /* !_SYS_KSE_H_ */