VT100 - Replace global buffer with per-terminal, further implementation of escape...
[tpg/acess2.git] / KernelLand / Kernel / time.c
index 449afcd..b0ea5e4 100644 (file)
@@ -77,17 +77,14 @@ void Timer_CallTimers()
        SHORTLOCK(&gTimers_ListLock);
        while( gTimers && gTimers->FiresAfter < now() )
        {
+               ASSERT( gTimers != gTimers->Next );     
                // Get timer from list
                tTimer  *timer = gTimers;
-       
-               ASSERT( gTimers != gTimers->Next );     
                gTimers = gTimers->Next;
        
                // Perform event
                if( timer->Callback ) {
                        LOG("Callback schedule %p", timer);
-                       // PROBLEM! Possibly causes rescheudle during interrupt
-//                     Mutex_Acquire( &timer->Lock );  // Released once the callback fires
                        Workqueue_AddWork(&gTimers_CallbackQueue, timer);
                }
                else {
@@ -117,7 +114,8 @@ tTimer *Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument)
  */
 void Time_ScheduleTimer(tTimer *Timer, int Delta)
 {
-       tTimer  *t, *p;
+       tTimer  *t;
+       tTimer  **prev_next;
 
        // Sanity checks
        if( !Timer )    return ;
@@ -134,9 +132,10 @@ void Time_ScheduleTimer(tTimer *Timer, int Delta)
        // Add into list (sorted)
        SHORTLOCK(&gTimers_ListLock);
 //     Mutex_Release( &Timer->Lock );  // Prevent deadlocks
-       for( p = (tTimer*)&gTimers, t = gTimers; t; p = t, t = t->Next )
+       for( prev_next = &gTimers, t = gTimers; t; prev_next = &t->Next, t = t->Next )
        {
-               ASSERT( p != t ); ASSERT( CheckMem(t, sizeof(tTimer)) );
+               ASSERT( prev_next != &t->Next );
+               ASSERT( CheckMem(t, sizeof(tTimer)) );
                if( t == Timer )
                {
                        LOG("Double schedule - increasing delta");
@@ -147,9 +146,9 @@ void Time_ScheduleTimer(tTimer *Timer, int Delta)
                if( t->FiresAfter > Timer->FiresAfter ) break;
        }
        Timer->Next = t;
-       p->Next = Timer;
+       *prev_next = Timer;
        Timer->bActive = 1;
-       LOG(" %p %p %p", p, Timer, t);
+       LOG(" prev_next=%p Timer=%p next=%p", prev_next, Timer, t);
        SHORTREL(&gTimers_ListLock);
 }
 
@@ -158,17 +157,19 @@ void Time_ScheduleTimer(tTimer *Timer, int Delta)
  */
 void Time_RemoveTimer(tTimer *Timer)
 {
-       tTimer  *t, *p;
+       tTimer  *t;
+       tTimer  **prev_next;
 
        if( !Timer )    return ;
        
        SHORTLOCK(&gTimers_ListLock);
-       for( p = (tTimer*)&gTimers, t = gTimers; t; p = t, t = t->Next )
+       for( prev_next = &gTimers, t = gTimers; t; prev_next = &t->Next, t = t->Next )
        {
-               ASSERT( p != t ); ASSERT( CheckMem(t, sizeof(tTimer)) );
+               ASSERT( prev_next != &t->Next );
+               ASSERT( CheckMem(t, sizeof(tTimer)) );
                if( t == Timer )
                {
-                       p->Next = t->Next;
+                       *prev_next = t->Next;
                        break ;
                }
        }
@@ -206,6 +207,7 @@ void Time_InitTimer(tTimer *Timer, tTimerCallback *Callback, void *Argument)
        Timer->Argument = Argument;
 //     memset( &Timer->Lock, 0, sizeof(Timer->Lock) );
        Timer->bActive = 0;
+       LOG("Initialised timer %p (cb=%p,arg=%p)", Timer, Callback, Argument);
 }
 
 /**
@@ -232,6 +234,7 @@ void Time_FreeTimer(tTimer *Timer)
  */
 void Time_Delay(int Delay)
 {
+       LOG("(%i)", Delay);
        tTimer  *t = &Proc_GetCurThread()->ThreadTimer;
        Time_InitTimer(t, NULL, NULL);
        Time_ScheduleTimer(t, Delay);

UCC git Repository :: git.ucc.asn.au