xref: /netbsd/lib/librumpuser/rumpfiber.h (revision d9a126e2)
1*d9a126e2Sjustin /*	$NetBSD: rumpfiber.h,v 1.4 2015/02/15 00:54:32 justin Exp $	*/
2cafcaf7fSpooka 
3ddcac26fSjustin /*
4ddcac26fSjustin  * Copyright (c) 2014 Justin Cormack.  All Rights Reserved.
5ddcac26fSjustin  *
6ddcac26fSjustin  * Redistribution and use in source and binary forms, with or without
7ddcac26fSjustin  * modification, are permitted provided that the following conditions
8ddcac26fSjustin  * are met:
9ddcac26fSjustin  * 1. Redistributions of source code must retain the above copyright
10ddcac26fSjustin  *    notice, this list of conditions and the following disclaimer.
11ddcac26fSjustin  * 2. Redistributions in binary form must reproduce the above copyright
12ddcac26fSjustin  *    notice, this list of conditions and the following disclaimer in the
13ddcac26fSjustin  *    documentation and/or other materials provided with the distribution.
14ddcac26fSjustin  *
15ddcac26fSjustin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16ddcac26fSjustin  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17ddcac26fSjustin  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18ddcac26fSjustin  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19ddcac26fSjustin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20ddcac26fSjustin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21ddcac26fSjustin  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22ddcac26fSjustin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23ddcac26fSjustin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24ddcac26fSjustin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25ddcac26fSjustin  * SUCH DAMAGE.
26ddcac26fSjustin  */
27ddcac26fSjustin 
28ddcac26fSjustin #include <sys/queue.h>
29ddcac26fSjustin 
30ddcac26fSjustin #include <stdint.h>
31ddcac26fSjustin #include <string.h>
32ddcac26fSjustin #include <time.h>
33ddcac26fSjustin #include <ucontext.h>
34ddcac26fSjustin #include <unistd.h>
35ddcac26fSjustin 
36ddcac26fSjustin struct thread {
37ddcac26fSjustin     char *name;
38ddcac26fSjustin     void *lwp;
39ddcac26fSjustin     void *cookie;
40ddcac26fSjustin     int64_t wakeup_time;
41ddcac26fSjustin     TAILQ_ENTRY(thread) thread_list;
42ddcac26fSjustin     ucontext_t ctx;
43*d9a126e2Sjustin     int flags;
44ddcac26fSjustin     int threrrno;
45ddcac26fSjustin };
46ddcac26fSjustin 
47ddcac26fSjustin #define RUNNABLE_FLAG   0x00000001
48ddcac26fSjustin #define THREAD_MUSTJOIN 0x00000002
49ddcac26fSjustin #define THREAD_JOINED   0x00000004
50ddcac26fSjustin #define THREAD_EXTSTACK 0x00000008
51ddcac26fSjustin #define THREAD_TIMEDOUT 0x00000010
52ddcac26fSjustin 
53ddcac26fSjustin #define STACKSIZE 65536
54ddcac26fSjustin 
55ddcac26fSjustin /* used by experimental _lwp code */
56ddcac26fSjustin void schedule(void);
57ddcac26fSjustin void wake(struct thread *thread);
58ddcac26fSjustin void block(struct thread *thread);
59ddcac26fSjustin struct thread *init_mainthread(void *);
60ddcac26fSjustin void exit_thread(void) __attribute__((noreturn));
61ddcac26fSjustin void set_sched_hook(void (*f)(void *, void *));
62ddcac26fSjustin int abssleep_real(uint64_t millisecs);
63ddcac26fSjustin struct thread* create_thread(const char *name, void *cookie,
64ddcac26fSjustin 			     void (*f)(void *), void *data,
65ddcac26fSjustin 			     void *stack, size_t stack_size);
66ddcac26fSjustin int is_runnable(struct thread *);
67ddcac26fSjustin void set_runnable(struct thread *);
68ddcac26fSjustin void clear_runnable(struct thread *);
69ddcac26fSjustin 
70