AmendHub

Download

jcs

/

subtext

/

uthread.h

 

(View History)

jcs   uthread: Add uthread_wakeup Latest amendment: 350 on 2023-03-02

1 /*
2 * Copyright (c) 2021 joshua stein <jcs@jcs.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <setjmp.h>
18
19 #ifndef __UTHREAD_H__
20 #define __UTHREAD_H__
21
22 #define NUM_UTHREADS 6
23
24 enum {
25 UTHREAD_STATE_DEAD,
26 UTHREAD_STATE_SETUP,
27 UTHREAD_STATE_RUNNING,
28 UTHREAD_STATE_YIELDING,
29 UTHREAD_STATE_SLEEPING,
30 UTHREAD_STATE_REPEAT
31 };
32
33 enum {
34 UTHREAD_SETJMP_DEFAULT,
35 UTHREAD_SETJMP_YIELDED
36 };
37
38 struct uthread {
39 short state;
40 short id;
41 jmp_buf env;
42 void (*func)(struct uthread *, void *);
43 void *arg;
44 unsigned long sleeping_until;
45 unsigned long stack_loc;
46 unsigned long stack_gap;
47 };
48
49 extern struct uthread *uthread_current;
50 extern unsigned long uthread_ApplLimit;
51
52 void uthread_init(void);
53 struct uthread *uthread_add(void *func, void *arg);
54 void uthread_yield(void);
55 void uthread_coordinate(void);
56 void uthread_msleep(unsigned long millis);
57 void uthread_wakeup(struct uthread *uthread);
58 void uthread_verify(void);
59
60 #endif /* __UTHREAD_H__ */