1 #include "thread.h"
2 #include <limits.h>
3 
4 extern void __exit_thread(void);
5 typedef void (*func_ptr)(void);
6 
kill_thread(struct thread * thread)7 void kill_thread(struct thread *thread)
8 {
9     irq_state_t irq;
10     struct thread_block *block;
11 
12     if (thread == current())
13 	__exit_thread();
14 
15     irq = irq_save();
16 
17     /*
18      * Muck with the stack so that the next time the thread is run then
19      * we end up going to __exit_thread.
20      */
21     thread->esp->eip = __exit_thread;
22     thread->prio = INT_MIN;
23 
24     block = thread->blocked;
25     if (block) {
26 	struct semaphore *sem = block->semaphore;
27 	/* Remove us from the queue and increase the count */
28 	block->list.next->prev = block->list.prev;
29 	block->list.prev->next = block->list.next;
30 	sem->count++;
31 
32 	thread->blocked = NULL;
33 	block->timed_out = true; /* Fake an immediate timeout */
34     }
35 
36     __schedule();
37 
38     irq_restore(irq);
39 }
40 
41 
42 
43