* The timer thread accessed a timer (to delete the TIMER_IS_RUNNING flag) after

it had been removed from the list. Now, I removed the flag again (but kept
  the flags field for now), and solved in a way that doesn't have this problem.
* This might have a positive effect on #2682.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27574 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-09-15 16:51:59 +00:00
parent 1dd3b2c724
commit 5d6d0dcfc3
1 changed files with 5 additions and 5 deletions

View File

@ -20,8 +20,6 @@
#include "stack_private.h" #include "stack_private.h"
#define TIMER_IS_RUNNING 0x80000000
// internal Fifo class which doesn't maintain it's own lock // internal Fifo class which doesn't maintain it's own lock
// TODO: do we need this one for anything? // TODO: do we need this one for anything?
class Fifo { class Fifo {
@ -58,6 +56,7 @@ static struct list sTimers;
static mutex sTimerLock; static mutex sTimerLock;
static sem_id sTimerWaitSem; static sem_id sTimerWaitSem;
static ConditionVariable sWaitForTimerCondition; static ConditionVariable sWaitForTimerCondition;
static net_timer* sCurrentTimer;
static thread_id sTimerThread; static thread_id sTimerThread;
static bigtime_t sTimerTimeout; static bigtime_t sTimerTimeout;
@ -441,14 +440,15 @@ timer_thread(void* /*data*/)
// execute timer // execute timer
list_remove_item(&sTimers, timer); list_remove_item(&sTimers, timer);
timer->due = -1; timer->due = -1;
timer->flags |= TIMER_IS_RUNNING; sCurrentTimer = timer;
mutex_unlock(&sTimerLock); mutex_unlock(&sTimerLock);
timer->hook(timer, timer->data); timer->hook(timer, timer->data);
mutex_lock(&sTimerLock); mutex_lock(&sTimerLock);
timer->flags &= ~TIMER_IS_RUNNING; sCurrentTimer = NULL;
sWaitForTimerCondition.NotifyAll(); sWaitForTimerCondition.NotifyAll();
timer = NULL; timer = NULL;
// restart scanning as we unlocked the list // restart scanning as we unlocked the list
} else { } else {
@ -543,7 +543,7 @@ wait_for_timer(struct net_timer* timer)
while (true) { while (true) {
MutexLocker locker(sTimerLock); MutexLocker locker(sTimerLock);
if (timer->due <= 0 && (timer->flags & TIMER_IS_RUNNING) == 0) if (timer->due <= 0 && sCurrentTimer != timer)
return; return;
// we actually need to wait for this timer // we actually need to wait for this timer