Skip to content
Snippets Groups Projects
Commit 3f95d728 authored by Oleg Hahm's avatar Oleg Hahm
Browse files

fix for #25 by using mutexes for hwtimer_wait

parent da7e0988
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* @author Heiko Will <hwill@inf.fu-berlin.de> * @author Heiko Will <hwill@inf.fu-berlin.de>
* @author Thomas Hillebrandt <hillebra@inf.fu-berlin.de> * @author Thomas Hillebrandt <hillebra@inf.fu-berlin.de>
* @author Kaspar Schleiser <kaspar.schleiser@fu-berlin.de> * @author Kaspar Schleiser <kaspar.schleiser@fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@fu-berlin.de>
* @} * @}
*/ */
...@@ -45,6 +46,10 @@ static void multiplexer(int source) ...@@ -45,6 +46,10 @@ static void multiplexer(int source)
timer[source].callback(timer[source].data); timer[source].callback(timer[source].data);
} }
static void hwtimer_releasemutex(void* mutex) {
mutex_unlock((mutex_t*) mutex);
}
static void hwtimer_wakeup(void *ptr) static void hwtimer_wakeup(void *ptr)
{ {
int pid = (int)ptr; int pid = (int)ptr;
...@@ -98,20 +103,25 @@ unsigned long hwtimer_now(void) ...@@ -98,20 +103,25 @@ unsigned long hwtimer_now(void)
void hwtimer_wait(unsigned long ticks) void hwtimer_wait(unsigned long ticks)
{ {
mutex_t mutex;
if (ticks <= 6 || inISR()) { if (ticks <= 6 || inISR()) {
hwtimer_spin(ticks); hwtimer_spin(ticks);
return; return;
} }
mutex_init(&mutex);
mutex_lock(&mutex);
/* -2 is to adjust the real value */ /* -2 is to adjust the real value */
int res = hwtimer_set(ticks - 2, hwtimer_wakeup, (void*)(unsigned int)(active_thread->pid)); int res = hwtimer_set(ticks - 2, hwtimer_releasemutex, &mutex);
if (res == -1) { if (res == -1) {
mutex_unlock(&mutex);
hwtimer_spin(ticks); hwtimer_spin(ticks);
return; return;
} }
thread_sleep(); /* try to lock mutex again will cause the thread to go into
* STATUS_MUTEX_BLOCKED until hwtimer fires the releasemutex */
mutex_lock(&mutex);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment