Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2108 → Rev 2109

/trunk/kernel/generic/include/proc/thread.h
243,7 → 243,6
extern void thread_destroy(thread_t *t);
extern void thread_update_accounting(void);
extern bool thread_exists(thread_t *t);
extern void thread_interrupt_sleep(thread_t *t);
 
/** Fpu context slab cache. */
extern slab_cache_t *fpu_context_slab;
/trunk/kernel/generic/include/synch/waitq.h
63,6 → 63,8
#define waitq_sleep(wq) \
waitq_sleep_timeout((wq), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
 
struct thread;
 
extern void waitq_initialize(waitq_t *wq);
extern int waitq_sleep_timeout(waitq_t *wq, uint32_t usec, int flags);
extern ipl_t waitq_sleep_prepare(waitq_t *wq);
70,6 → 72,7
extern void waitq_sleep_finish(waitq_t *wq, int rc, ipl_t ipl);
extern void waitq_wakeup(waitq_t *wq, bool all);
extern void _waitq_wakeup_unsafe(waitq_t *wq, bool all);
extern void waitq_interrupt_sleep(struct thread *t);
 
#endif
 
/trunk/kernel/generic/include/ddi/irq.h
83,8 → 83,6
struct irq;
typedef void (* irq_handler_t)(struct irq *irq, void *arg, ...);
 
 
 
/** IPC notification config structure.
*
* Primarily, this structure is encapsulated in the irq_t structure.
/trunk/kernel/generic/src/synch/waitq.c
116,7 → 116,59
spinlock_unlock(&threads_lock);
}
 
/** Interrupt sleeping thread.
*
* This routine attempts to interrupt a thread from its sleep in a waitqueue.
* If the thread is not found sleeping, no action is taken.
*
* @param t Thread to be interrupted.
*/
void waitq_interrupt_sleep(thread_t *t)
{
waitq_t *wq;
bool do_wakeup = false;
ipl_t ipl;
 
ipl = interrupts_disable();
spinlock_lock(&threads_lock);
if (!thread_exists(t))
goto out;
 
grab_locks:
spinlock_lock(&t->lock);
if ((wq = t->sleep_queue)) { /* assignment */
if (!(t->sleep_interruptible)) {
/*
* The sleep cannot be interrupted.
*/
spinlock_unlock(&t->lock);
goto out;
}
if (!spinlock_trylock(&wq->lock)) {
spinlock_unlock(&t->lock);
goto grab_locks; /* avoid deadlock */
}
 
if (t->timeout_pending && timeout_unregister(&t->sleep_timeout))
t->timeout_pending = false;
 
list_remove(&t->wq_link);
t->saved_context = t->sleep_interruption_context;
do_wakeup = true;
t->sleep_queue = NULL;
spinlock_unlock(&wq->lock);
}
spinlock_unlock(&t->lock);
 
if (do_wakeup)
thread_ready(t);
 
out:
spinlock_unlock(&threads_lock);
interrupts_restore(ipl);
}
 
/** Sleep until either wakeup, timeout or interruption occurs
*
* This is a sleep implementation which allows itself to time out or to be
/trunk/kernel/generic/src/proc/task.c
42,6 → 42,7
#include <mm/as.h>
#include <mm/slab.h>
#include <synch/spinlock.h>
#include <synch/waitq.h>
#include <arch.h>
#include <panic.h>
#include <adt/btree.h>
363,7 → 364,7
spinlock_unlock(&thr->lock);
if (sleeping)
thread_interrupt_sleep(thr);
waitq_interrupt_sleep(thr);
}
spinlock_unlock(&ta->lock);
/trunk/kernel/generic/src/proc/thread.c
678,59 → 678,6
return 0;
}
 
/** Interrupt sleeping thread.
*
* This routine attempts to interrupt a thread from its sleep in a waitqueue.
* If the thread is not found sleeping, no action is taken.
*
* @param t Thread to be interrupted.
*/
void thread_interrupt_sleep(thread_t *t)
{
waitq_t *wq;
bool do_wakeup = false;
ipl_t ipl;
 
ipl = interrupts_disable();
spinlock_lock(&threads_lock);
if (!thread_exists(t))
goto out;
 
grab_locks:
spinlock_lock(&t->lock);
if ((wq = t->sleep_queue)) { /* assignment */
if (!(t->sleep_interruptible)) {
/*
* The sleep cannot be interrupted.
*/
spinlock_unlock(&t->lock);
goto out;
}
if (!spinlock_trylock(&wq->lock)) {
spinlock_unlock(&t->lock);
goto grab_locks; /* avoid deadlock */
}
 
if (t->timeout_pending && timeout_unregister(&t->sleep_timeout))
t->timeout_pending = false;
 
list_remove(&t->wq_link);
t->saved_context = t->sleep_interruption_context;
do_wakeup = true;
t->sleep_queue = NULL;
spinlock_unlock(&wq->lock);
}
spinlock_unlock(&t->lock);
 
if (do_wakeup)
thread_ready(t);
 
out:
spinlock_unlock(&threads_lock);
interrupts_restore(ipl);
}
 
/** @}
*/