Subversion Repositories HelenOS

Rev

Rev 177 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 177 Rev 410
Line 43... Line 43...
43
#define THREAD_STACK_SIZE   STACK_SIZE
43
#define THREAD_STACK_SIZE   STACK_SIZE
44
 
44
 
45
#define THREAD_USER_STACK   1
45
#define THREAD_USER_STACK   1
46
 
46
 
47
enum state {
47
enum state {
48
    Invalid,
48
    Invalid,    /**< It is an error, if thread is found in this state. */
49
    Running,
49
    Running,    /**< State of a thread that is currently executing on some CPU. */
50
    Sleeping,
50
    Sleeping,   /**< Thread in this state is waiting for an event. */
51
    Ready,
51
    Ready,      /**< State of threads in a run queue. */
52
    Entering,
52
    Entering,   /**< Threads are in this state before they are first readied. */
53
    Exiting
53
    Exiting     /**< After a thread calls thread_exit(), it is put into Exiting state. */
54
};
54
};
55
 
55
 
56
extern char *thread_states[];
56
extern char *thread_states[];
57
 
57
 
58
#define X_WIRED     (1<<0)
58
#define X_WIRED     (1<<0)
59
#define X_STOLEN    (1<<1)
59
#define X_STOLEN    (1<<1)
60
 
60
 
61
struct thread {
61
struct thread {
62
    link_t rq_link;             /* run queue link */
62
    link_t rq_link;             /**< Run queue link. */
63
    link_t wq_link;             /* wait queue link */
63
    link_t wq_link;             /**< Wait queue link. */
64
    link_t th_link;             /* links to threads within the parent task*/
64
    link_t th_link;             /**< Links to threads within containing task. */
65
    link_t threads_link;
65
    link_t threads_link;            /**< Link to the list of all threads. */
66
   
66
   
67
    /* items below are protected by lock */
67
    /* items below are protected by lock */
68
    spinlock_t lock;
68
    spinlock_t lock;
69
 
69
 
70
    void (* thread_code)(void *);
70
    void (* thread_code)(void *);       /**< Function implementing the thread. */
71
    void *thread_arg;
71
    void *thread_arg;           /**< Argument passed to thread_code() function. */
-
 
72
 
-
 
73
    context_t saved_context;        /**< From here, the stored context is restored when the thread is scheduled. */
-
 
74
    context_t sleep_timeout_context;    /**< From here, the stored failover context is restored when sleep times out. */
-
 
75
 
-
 
76
    waitq_t *sleep_queue;           /**< Wait queue in which this thread sleeps. */
-
 
77
    timeout_t sleep_timeout;        /**< Timeout used for timeoutable sleeping.  */
-
 
78
    volatile int timeout_pending;       /**< Flag signalling sleep timeout in progress. */
72
 
79
 
73
    context_t saved_context;
-
 
74
    context_t sleep_timeout_context;
-
 
75
    fpu_context_t saved_fpu_context;
80
    fpu_context_t saved_fpu_context;
76
    int fpu_context_exists;
81
    int fpu_context_exists;
77
 
82
 
78
    /*
83
    /*
79
     * Defined only if thread doesn't run.
84
     * Defined only if thread doesn't run.
80
     * It means that fpu context is in CPU that last time executes this thread.
85
     * It means that fpu context is in CPU that last time executes this thread.
81
     * This disables migration
86
     * This disables migration
82
     */
87
     */
83
    int fpu_context_engaged;
88
    int fpu_context_engaged;
84
 
89
 
85
    waitq_t *sleep_queue;
-
 
86
    timeout_t sleep_timeout;
-
 
87
    volatile int timeout_pending;
-
 
88
 
-
 
89
    rwlock_type_t rwlock_holder_type;
90
    rwlock_type_t rwlock_holder_type;
90
    void (* call_me)(void *);
-
 
91
    void *call_me_with;
-
 
92
 
91
 
-
 
92
    void (* call_me)(void *);       /**< Funtion to be called in scheduler before the thread is put asleep. */
-
 
93
    void *call_me_with;         /**< Argument passed to call_me(). */
-
 
94
 
93
    int state;
95
    state_t state;              /**< Thread's state. */
94
    int flags;
96
    int flags;              /**< Thread's flags. */
95
   
97
   
96
    cpu_t *cpu;
98
    cpu_t *cpu;             /**< Thread's CPU. */
97
    task_t *task;
99
    task_t *task;               /**< Containing task. */
98
 
100
 
99
    __u64 ticks;
101
    __u64 ticks;                /**< Ticks before preemption. */
100
 
102
 
-
 
103
    int pri;                /**< Thread's priority. Implemented as index of run queue. */
101
    __u32 tid;
104
    __u32 tid;              /**< Thread ID. */
102
   
-
 
103
    int pri;
-
 
104
   
105
   
105
    ARCH_THREAD_DATA;
106
    ARCH_THREAD_DATA;           /**< Architecture-specific data. */
106
 
107
 
107
    __u8 *kstack;
108
    __u8 *kstack;               /**< Thread's kernel stack. */
108
    __u8 *ustack;
109
    __u8 *ustack;               /**< Thread's user stack. */
109
};
110
};
110
 
111
 
111
extern spinlock_t threads_lock;
112
extern spinlock_t threads_lock;         /**< Lock protecting threads_head list. */
112
extern link_t threads_head;
113
extern link_t threads_head;         /**< List of all threads in the system. */
113
 
114
 
114
static void cushion(void);
115
static void cushion(void);
115
 
116
 
116
extern void thread_init(void);
117
extern void thread_init(void);
117
extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags);
118
extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags);