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