Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2335 → Rev 2336

/branches/rcu/kernel/generic/src/time/timeout.c
1,5 → 1,5
/*
* Copyright (c) 2001-2004 Jakub Jermar
* Copyright (C) 2001-2004 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
45,6 → 45,7
#include <arch/asm.h>
#include <arch.h>
 
 
/** Initialize timeouts
*
* Initialize kernel timeouts.
53,7 → 54,12
void timeout_init(void)
{
spinlock_initialize(&CPU->timeoutlock, "timeout_lock");
 
#ifdef CONFIG_TIMEOUT_EXTAVL_TREE
extavltree_create(&CPU->timeout_active_tree);
#else
list_initialize(&CPU->timeout_active_head);
#endif
}
 
 
67,10 → 73,15
void timeout_reinitialize(timeout_t *t)
{
t->cpu = NULL;
t->ticks = 0;
t->handler = NULL;
t->arg = NULL;
#ifdef CONFIG_TIMEOUT_EXTAVL_TREE
extavltree_node_initialize(&t->node);
#else
t->ticks = 0;
link_initialize(&t->link);
#endif
}
 
 
87,7 → 98,90
timeout_reinitialize(t);
}
 
#ifdef CONFIG_TIMEOUT_EXTAVL_TREE
/** Register timeout
*
* Insert timeout handler f (with argument arg)
* to timeout list and make it execute in
* time microseconds (or slightly more).
*
* @param t Timeout structure.
* @param time Number of usec in the future to execute
* the handler.
* @param f Timeout handler function.
* @param arg Timeout handler argument.
*
*/
void timeout_register(timeout_t *t, uint64_t time, timeout_handler_t f, void *arg)
{
ipl_t ipl;
 
ipl = interrupts_disable();
spinlock_lock(&CPU->timeoutlock);
spinlock_lock(&t->lock);
 
if (t->cpu)
panic("t->cpu != 0");
t->cpu = CPU;
//tiky nejsou, musim zmenit klice primo v uzlech
t->handler = f;
t->arg = arg;
 
extavltree_insert(&CPU->timeout_active_tree,&t->node);
spinlock_unlock(&t->lock);
spinlock_unlock(&CPU->timeoutlock);
interrupts_restore(ipl);
}
 
 
/** Unregister timeout
*
* Remove timeout from timeout list.
*
* @param t Timeout to unregister.
*
* @return true on success, false on failure.
*/
bool timeout_unregister(timeout_t *t)
{
ipl_t ipl;
 
grab_locks:
ipl = interrupts_disable();
spinlock_lock(&t->lock);
if (!t->cpu) {
spinlock_unlock(&t->lock);
interrupts_restore(ipl);
return false;
}
if (!spinlock_trylock(&t->cpu->timeoutlock)) {
spinlock_unlock(&t->lock);
interrupts_restore(ipl);
goto grab_locks;
}
/*
* Now we know for sure that t hasn't been activated yet
* and is lurking in t->cpu->timeout_active_head queue.
*/
 
extavltree_delete(&CPU->timeout_active_tree,&t->node);
spinlock_unlock(&t->cpu->timeoutlock);
 
timeout_reinitialize(t);
spinlock_unlock(&t->lock);
 
interrupts_restore(ipl);
return true;
}
 
#else
 
/** Register timeout
*
* Insert timeout handler f (with argument arg)
174,7 → 268,6
timeout_t *hlp;
link_t *l;
ipl_t ipl;
DEADLOCK_PROBE_INIT(p_tolock);
 
grab_locks:
ipl = interrupts_disable();
186,8 → 279,7
}
if (!spinlock_trylock(&t->cpu->timeoutlock)) {
spinlock_unlock(&t->lock);
interrupts_restore(ipl);
DEADLOCK_PROBE(p_tolock, DEADLOCK_THRESHOLD);
interrupts_restore(ipl);
goto grab_locks;
}
214,5 → 306,6
return true;
}
 
#endif
/** @}
*/