Prex Home / Browse Source - Prex Version: 0.9.0

root/sys/include/thread.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*-
   2  * Copyright (c) 2005-2009, Kohsuke Ohtani
   3  * All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  * 1. Redistributions of source code must retain the above copyright
   9  *    notice, this list of conditions and the following disclaimer.
  10  * 2. Redistributions in binary form must reproduce the above copyright
  11  *    notice, this list of conditions and the following disclaimer in the
  12  *    documentation and/or other materials provided with the distribution.
  13  * 3. Neither the name of the author nor the names of any co-contributors
  14  *    may be used to endorse or promote products derived from this software
  15  *    without specific prior written permission.
  16  *
  17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27  * SUCH DAMAGE.
  28  */
  29 
  30 #ifndef _THREAD_H
  31 #define _THREAD_H
  32 
  33 #include <types.h>
  34 #include <sys/cdefs.h>
  35 #include <sys/queue.h>
  36 #include <sys/list.h>
  37 #include <sys/sysinfo.h>
  38 #include <event.h>
  39 #include <timer.h>
  40 #include <hal.h>
  41 
  42 /*
  43  * Description of a thread.
  44  */
  45 struct thread {
  46         struct list     link;           /* linkage on all threads */
  47         struct list     task_link;      /* linkage on thread list in task */
  48         struct queue    sched_link;     /* linkage on scheduling queue */
  49         task_t          task;           /* task to which I belong */
  50         int             state;          /* thread state */
  51         int             policy;         /* scheduling policy */
  52         int             priority;       /* current priority */
  53         int             basepri;        /* statical base priority */
  54         int             timeleft;       /* remaining ticks to run */
  55         u_int           time;           /* total running time */
  56         int             resched;        /* true if rescheduling is needed */
  57         int             locks;          /* schedule lock counter */
  58         int             suscnt;         /* suspend count */
  59         struct event    *slpevt;        /* event we are waiting on */
  60         int             slpret;         /* return value for sched_tleep */
  61         struct timer    timeout;        /* thread timer */
  62         struct timer    *periodic;      /* pointer to periodic timer */
  63         uint32_t        excbits;        /* bitmap of pending exceptions */
  64         struct list     mutexes;        /* mutexes locked by this thread */
  65         mutex_t         mutex_waiting;  /* mutex pointer currently waiting */
  66         struct queue    ipc_link;       /* linkage on IPC queue */
  67         void            *msgaddr;       /* kernel address of IPC message */
  68         size_t          msgsize;        /* size of IPC message */
  69         thread_t        sender;         /* thread that sends IPC message */
  70         thread_t        receiver;       /* thread that receives IPC message */
  71         object_t        sendobj;        /* IPC object sending to */
  72         object_t        recvobj;        /* IPC object receiving from */
  73         void            *kstack;        /* base address of kernel stack */
  74         struct context  ctx;            /* machine specific context */
  75 };
  76 
  77 /*
  78  * Thread state
  79  */
  80 #define TS_RUN          0x00    /* running or ready to run */
  81 #define TS_SLEEP        0x01    /* awaiting an event */
  82 #define TS_SUSP         0x02    /* suspend count is not 0 */
  83 #define TS_EXIT         0x04    /* terminated */
  84 
  85 /*
  86  * Sleep result
  87  */
  88 #define SLP_SUCCESS     0       /* success */
  89 #define SLP_BREAK       1       /* break due to some reasons */
  90 #define SLP_TIMEOUT     2       /* timeout */
  91 #define SLP_INVAL       3       /* target event becomes invalid */
  92 #define SLP_INTR        4       /* interrupted by exception */
  93 
  94 /*
  95  * Scheduling operations for thread_schedparam().
  96  */
  97 #define SOP_GETPRI      0       /* get scheduling priority */
  98 #define SOP_SETPRI      1       /* set scheduling priority */
  99 #define SOP_GETPOLICY   2       /* get scheduling policy */
 100 #define SOP_SETPOLICY   3       /* set scheduling policy */
 101 
 102 __BEGIN_DECLS
 103 int      thread_create(task_t, thread_t *);
 104 int      thread_terminate(thread_t);
 105 void     thread_destroy(thread_t);
 106 int      thread_load(thread_t, void (*)(void), void *);
 107 thread_t thread_self(void);
 108 int      thread_valid(thread_t);
 109 void     thread_yield(void);
 110 int      thread_suspend(thread_t);
 111 int      thread_resume(thread_t);
 112 int      thread_schedparam(thread_t, int, int *);
 113 void     thread_idle(void);
 114 int      thread_info(struct threadinfo *);
 115 thread_t kthread_create(void (*)(void *), void *, int);
 116 void     kthread_terminate(thread_t);
 117 void     thread_init(void);
 118 __END_DECLS
 119 
 120 #endif /* !_THREAD_H */

/* [<][>][^][v][top][bottom][index][help] */