/* * Copyright (c) 2021 joshua stein * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #ifndef __UTHREAD_H__ #define __UTHREAD_H__ #define NUM_UTHREADS 6 enum { UTHREAD_STATE_DEAD, UTHREAD_STATE_SETUP, UTHREAD_STATE_RUNNING, UTHREAD_STATE_YIELDING, UTHREAD_STATE_SLEEPING, UTHREAD_STATE_REPEAT }; enum { UTHREAD_SETJMP_DEFAULT, UTHREAD_SETJMP_YIELDED }; struct uthread { short state; short id; jmp_buf env; void (*func)(struct uthread *, void *); void *arg; unsigned long sleeping_until; unsigned long stack_loc; unsigned long stack_gap; }; extern struct uthread *uthread_current; extern unsigned long uthread_ApplLimit; void uthread_init(void); struct uthread *uthread_add(void *func, void *arg); void uthread_yield(void); void uthread_coordinate(void); void uthread_msleep(unsigned long millis); void uthread_wakeup(struct uthread *uthread); void uthread_verify(void); #endif /* __UTHREAD_H__ */