]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/kse.h
This commit was generated by cvs2svn to compensate for changes in r128456,
[FreeBSD/FreeBSD.git] / sys / sys / kse.h
1 /*
2  * Copyright (C) 2001 Julian Elischer <julian@freebsd.org>
3  * for the FreeBSD Foundation.
4  *
5  *  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
17  *
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
28  * DAMAGE.
29  *
30  * $FreeBSD$
31  */
32
33 #ifndef _SYS_KSE_H_
34 #define _SYS_KSE_H_
35
36 #include <sys/ucontext.h>
37 #include <sys/time.h>
38 #include <sys/signal.h>
39
40 /*
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.
45  */
46 struct kse_mailbox;
47
48 typedef void    kse_func_t(struct kse_mailbox *);
49
50 /*
51  * Thread mailbox.
52  *
53  * This describes a user thread to the kernel scheduler.
54  */
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 */
60         uint32_t                tm_uticks;
61         uint32_t                tm_sticks;
62         siginfo_t               tm_syncsig;
63         int                     tm_spare[8];
64 };
65
66 /*
67  * KSE mailbox.
68  *
69  * Communication path between the UTS and the kernel scheduler specific to
70  * a single KSE.
71  */
72 struct kse_mailbox {
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 */
83         int                     km_spare[8];
84 };
85
86 #define KSE_VER_0       0
87 #define KSE_VERSION     KSE_VER_0
88
89 /* These flags are kept in km_flags */
90 #define KMF_NOUPCALL            0x01
91 #define KMF_NOCOMPLETED         0x02
92 #define KMF_DONE                0x04
93 #define KMF_BOUND               0x08
94 #define KMF_WAITSIGEVENT        0x10
95
96 /* These flags are kept in tm_flags */
97 #define TMF_NOUPCALL            0x01
98
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
104
105 #ifndef _KERNEL
106 int     kse_create(struct kse_mailbox *, int);
107 int     kse_exit(void);
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 */
113
114 #endif  /* !_SYS_KSE_H_ */