Adding upstream version 6.02+dfsg.
[syslinux-debian/hramrach.git] / core / thread / kill_thread.c
blobc22517c64d96368f68b83a2c1724deff89c13ce7
1 #include "thread.h"
2 #include <limits.h>
4 extern void __exit_thread(void);
5 typedef void (*func_ptr)(void);
7 void kill_thread(struct thread *thread)
9 irq_state_t irq;
10 struct thread_block *block;
12 if (thread == current())
13 __exit_thread();
15 irq = irq_save();
18 * Muck with the stack so that the next time the thread is run then
19 * we end up going to __exit_thread.
21 thread->esp->eip = __exit_thread;
22 thread->prio = INT_MIN;
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++;
32 thread->blocked = NULL;
33 block->timed_out = true; /* Fake an immediate timeout */
36 __schedule();
38 irq_restore(irq);