[BACK]Return to thread.h CVS log [TXT][DIR] Up to [local] / prex-old / sys / include

Annotation of prex-old/sys/include/thread.h, Revision 1.1.1.1.2.1

1.1       nbrk        1: /*-
1.1.1.1.2.1! nbrk        2:  * Copyright (c) 2005-2008, Kohsuke Ohtani
1.1       nbrk        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 <queue.h>
                     34: #include <event.h>
                     35: #include <timer.h>
                     36: #include <arch.h>
                     37:
                     38: struct mutex;
                     39:
                     40: /*
                     41:  * Description of a thread.
                     42:  */
                     43: struct thread {
                     44:        int             magic;          /* magic number */
                     45:        task_t          task;           /* pointer to owner task */
                     46:        struct list     task_link;      /* link for threads in same task */
                     47:        struct queue    link;           /* linkage on scheduling queue */
                     48:        int             state;          /* thread state */
                     49:        int             policy;         /* scheduling policy */
                     50:        int             prio;           /* current priority */
1.1.1.1.2.1! nbrk       51:        int             baseprio;       /* base priority */
        !            52:        int             timeleft;       /* remaining ticks to run */
        !            53:        u_int           time;           /* total running time */
        !            54:        int             resched;        /* true if rescheduling is needed */
        !            55:        int             locks;          /* schedule lock counter */
        !            56:        int             suscnt;         /* suspend counter */
        !            57:        struct event    *slpevt;        /* sleep event */
        !            58:        int             slpret;         /* sleep result code */
1.1       nbrk       59:        struct timer    timeout;        /* thread timer */
                     60:        struct timer    *periodic;      /* pointer to periodic timer */
1.1.1.1.2.1! nbrk       61:        uint32_t        excbits;        /* bitmap of pending exceptions */
1.1       nbrk       62:        struct queue    ipc_link;       /* linkage on IPC queue */
1.1.1.1.2.1! nbrk       63:        void            *msgaddr;       /* kernel address of IPC message */
        !            64:        size_t          msgsize;        /* size of IPC message */
        !            65:        thread_t        sender;         /* thread that sends IPC message */
        !            66:        thread_t        receiver;       /* thread that receives IPC message */
        !            67:        object_t        sendobj;        /* IPC object sending to */
        !            68:        object_t        recvobj;        /* IPC object receiving from */
1.1       nbrk       69:        struct list     mutexes;        /* mutexes locked by this thread */
                     70:        struct mutex    *wait_mutex;    /* mutex pointer currently waiting */
                     71:        void            *kstack;        /* base address of kernel stack */
1.1.1.1.2.1! nbrk       72:        struct context  ctx;            /* machine specific context */
1.1       nbrk       73: };
                     74:
                     75: #define thread_valid(th) (kern_area(th) && ((th)->magic == THREAD_MAGIC))
                     76:
                     77: /*
                     78:  * Thread state
                     79:  */
                     80: #define TH_RUN         0x00    /* running or ready to run */
                     81: #define TH_SLEEP       0x01    /* awaiting an event */
                     82: #define TH_SUSPEND     0x02    /* suspend count is not 0 */
                     83: #define TH_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:  * Priorities
1.1.1.1.2.1! nbrk       96:  * Probably should not be altered too much.
1.1       nbrk       97:  */
                     98: #define PRIO_TIMER     15      /* priority for timer thread */
                     99: #define PRIO_IST       16      /* top priority for interrupt threads */
                    100: #define PRIO_DPC       33      /* priority for Deferred Procedure Call */
                    101: #define PRIO_IDLE      255     /* priority for idle thread */
                    102: #define PRIO_USER      CONFIG_USER_PRIO
                    103:
                    104: #define MAX_PRIO       0
                    105: #define MIN_PRIO       255
1.1.1.1.2.1! nbrk      106: #define NPRIO          256     /* number of thread priority */
1.1       nbrk      107:
                    108: /*
                    109:  * Scheduling operations for thread_schedparam().
                    110:  */
                    111: #define OP_GETPRIO     0       /* get scheduling priority */
                    112: #define OP_SETPRIO     1       /* set scheduling priority */
                    113: #define OP_GETPOLICY   2       /* get scheduling policy */
                    114: #define OP_SETPOLICY   3       /* set scheduling policy */
                    115:
                    116: extern int      thread_create(task_t, thread_t *);
                    117: extern int      thread_terminate(thread_t);
                    118: extern int      thread_load(thread_t, void (*)(void), void *);
                    119: extern thread_t         thread_self(void);
                    120: extern void     thread_yield(void);
                    121: extern int      thread_suspend(thread_t);
                    122: extern int      thread_resume(thread_t);
                    123: extern int      thread_schedparam(thread_t, int, int *);
                    124: extern void     thread_idle(void);
                    125: extern int      thread_info(struct info_thread *);
                    126: extern void     thread_dump(void);
                    127: extern void     thread_init(void);
1.1.1.1.2.1! nbrk      128:
        !           129: /* for kernel thread */
        !           130: extern thread_t         kthread_create(void (*)(void *), void *, int);
        !           131: extern void     kthread_terminate(thread_t);
1.1       nbrk      132:
                    133: #endif /* !_THREAD_H */

CVSweb