Annotation of prex-old/sys/include/thread.h, Revision 1.1
1.1 ! nbrk 1: /*-
! 2: * Copyright (c) 2005-2007, 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 <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 */
! 51: int base_prio; /* base priority */
! 52: int ticks_left; /* remaining ticks to run */
! 53: u_int total_ticks; /* total running ticks */
! 54: int need_resched; /* true if rescheduling is needed */
! 55: int lock_count; /* schedule lock counter */
! 56: int suspend_count; /* suspend counter */
! 57: struct event *sleep_event; /* sleep event */
! 58: int sleep_result; /* sleep result */
! 59: struct timer timeout; /* thread timer */
! 60: struct timer *periodic; /* pointer to periodic timer */
! 61: struct queue ipc_link; /* linkage on IPC queue */
! 62: void *msg_addr; /* kernel address of IPC message */
! 63: size_t msg_size; /* size of IPC message */
! 64: struct thread *sender; /* thread that sends IPC message */
! 65: struct thread *receiver; /* thread that receives IPC message */
! 66: object_t send_obj; /* IPC object sending to */
! 67: object_t recv_obj; /* IPC object receiving from */
! 68: uint32_t exc_bitmap; /* bitmap of pending exceptions */
! 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 */
! 72: struct context context; /* machine specific context */
! 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
! 96: */
! 97: #define PRIO_TIMER 15 /* priority for timer thread */
! 98: #define PRIO_IST 16 /* top priority for interrupt threads */
! 99: #define PRIO_DPC 33 /* priority for Deferred Procedure Call */
! 100: #define PRIO_IDLE 255 /* priority for idle thread */
! 101: #define PRIO_USER CONFIG_USER_PRIO
! 102:
! 103: #define MAX_PRIO 0
! 104: #define MIN_PRIO 255
! 105: #define NR_PRIOS 256 /* number of thread priority */
! 106:
! 107: /*
! 108: * Scheduling operations for thread_schedparam().
! 109: */
! 110: #define OP_GETPRIO 0 /* get scheduling priority */
! 111: #define OP_SETPRIO 1 /* set scheduling priority */
! 112: #define OP_GETPOLICY 2 /* get scheduling policy */
! 113: #define OP_SETPOLICY 3 /* set scheduling policy */
! 114:
! 115: extern int thread_create(task_t, thread_t *);
! 116: extern int thread_terminate(thread_t);
! 117: extern int thread_kill(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 thread_t kernel_thread(int, void (*)(u_long), u_long);
! 127: extern void thread_dump(void);
! 128: extern void thread_init(void);
! 129:
! 130: #endif /* !_THREAD_H */
CVSweb