Rev 10 | Rev 16 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 10 | Rev 15 | ||
---|---|---|---|
Line 64... | Line 64... | ||
64 | * |
64 | * |
65 | * cpu_priority_high()'d |
65 | * cpu_priority_high()'d |
66 | */ |
66 | */ |
67 | void cushion(void) |
67 | void cushion(void) |
68 | { |
68 | { |
69 | void (*f)(void *) = the->thread->thread_code; |
69 | void (*f)(void *) = THREAD->thread_code; |
70 | void *arg = the->thread->thread_arg; |
70 | void *arg = THREAD->thread_arg; |
71 | 71 | ||
72 | /* this is where each thread wakes up after its creation */ |
72 | /* this is where each thread wakes up after its creation */ |
73 | spinlock_unlock(&the->thread->lock); |
73 | spinlock_unlock(&THREAD->lock); |
74 | cpu_priority_low(); |
74 | cpu_priority_low(); |
75 | 75 | ||
76 | f(arg); |
76 | f(arg); |
77 | thread_exit(); |
77 | thread_exit(); |
78 | /* not reached */ |
78 | /* not reached */ |
79 | } |
79 | } |
80 | 80 | ||
81 | void thread_init(void) |
81 | void thread_init(void) |
82 | { |
82 | { |
83 | the->thread = NULL; |
83 | THREAD = NULL; |
84 | nrdy = 0; |
84 | nrdy = 0; |
85 | spinlock_initialize(&threads_lock); |
85 | spinlock_initialize(&threads_lock); |
86 | list_initialize(&threads_head); |
86 | list_initialize(&threads_head); |
87 | } |
87 | } |
88 | 88 | ||
Line 212... | Line 212... | ||
212 | { |
212 | { |
213 | pri_t pri; |
213 | pri_t pri; |
214 | 214 | ||
215 | restart: |
215 | restart: |
216 | pri = cpu_priority_high(); |
216 | pri = cpu_priority_high(); |
217 | spinlock_lock(&the->thread->lock); |
217 | spinlock_lock(&THREAD->lock); |
218 | if (the->thread->timeout_pending) { /* busy waiting for timeouts in progress */ |
218 | if (THREAD->timeout_pending) { /* busy waiting for timeouts in progress */ |
219 | spinlock_unlock(&the->thread->lock); |
219 | spinlock_unlock(&THREAD->lock); |
220 | cpu_priority_restore(pri); |
220 | cpu_priority_restore(pri); |
221 | goto restart; |
221 | goto restart; |
222 | } |
222 | } |
223 | the->thread->state = Exiting; |
223 | THREAD->state = Exiting; |
224 | spinlock_unlock(&the->thread->lock); |
224 | spinlock_unlock(&THREAD->lock); |
225 | scheduler(); |
225 | scheduler(); |
226 | } |
226 | } |
227 | 227 | ||
228 | void thread_sleep(__u32 sec) |
228 | void thread_sleep(__u32 sec) |
229 | { |
229 | { |
Line 245... | Line 245... | ||
245 | void thread_register_call_me(void (* call_me)(void *), void *call_me_with) |
245 | void thread_register_call_me(void (* call_me)(void *), void *call_me_with) |
246 | { |
246 | { |
247 | pri_t pri; |
247 | pri_t pri; |
248 | 248 | ||
249 | pri = cpu_priority_high(); |
249 | pri = cpu_priority_high(); |
250 | spinlock_lock(&the->thread->lock); |
250 | spinlock_lock(&THREAD->lock); |
251 | the->thread->call_me = call_me; |
251 | THREAD->call_me = call_me; |
252 | the->thread->call_me_with = call_me_with; |
252 | THREAD->call_me_with = call_me_with; |
253 | spinlock_unlock(&the->thread->lock); |
253 | spinlock_unlock(&THREAD->lock); |
254 | cpu_priority_restore(pri); |
254 | cpu_priority_restore(pri); |
255 | } |
255 | } |