git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Kernel - Working on allowing \0 out debug
[tpg/acess2.git]
/
KernelLand
/
Kernel
/
time.c
diff --git
a/KernelLand/Kernel/time.c
b/KernelLand/Kernel/time.c
index
d8c2924
..
b0ea5e4
100644
(file)
--- a/
KernelLand/Kernel/time.c
+++ b/
KernelLand/Kernel/time.c
@@
-8,19
+8,11
@@
#define DEBUG 0
#include <acess.h>
#include <timers.h>
#define DEBUG 0
#include <acess.h>
#include <timers.h>
+#include <timers_int.h>
#include <events.h>
#include <hal_proc.h> // Proc_GetCurThread
#include <workqueue.h>
#include <events.h>
#include <hal_proc.h> // Proc_GetCurThread
#include <workqueue.h>
-
-// === TYPEDEFS ===
-struct sTimer {
- tTimer *Next;
- Sint64 FiresAfter;
- void (*Callback)(void*);
- void *Argument;
-// tMutex Lock;
- BOOL bActive;
-};
+#include <threads_int.h> // Used to get thread timer
// === PROTOTYPES ===
void Timer_CallbackThread(void *Unused);
// === PROTOTYPES ===
void Timer_CallbackThread(void *Unused);
@@
-85,17
+77,14
@@
void Timer_CallTimers()
SHORTLOCK(&gTimers_ListLock);
while( gTimers && gTimers->FiresAfter < now() )
{
SHORTLOCK(&gTimers_ListLock);
while( gTimers && gTimers->FiresAfter < now() )
{
+ ASSERT( gTimers != gTimers->Next );
// Get timer from list
tTimer *timer = gTimers;
// Get timer from list
tTimer *timer = gTimers;
-
- ASSERT( gTimers != gTimers->Next );
gTimers = gTimers->Next;
// Perform event
if( timer->Callback ) {
LOG("Callback schedule %p", timer);
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 {
Workqueue_AddWork(&gTimers_CallbackQueue, timer);
}
else {
@@
-125,7
+114,8
@@
tTimer *Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument)
*/
void Time_ScheduleTimer(tTimer *Timer, int Delta)
{
*/
void Time_ScheduleTimer(tTimer *Timer, int Delta)
{
- tTimer *t, *p;
+ tTimer *t;
+ tTimer **prev_next;
// Sanity checks
if( !Timer ) return ;
// Sanity checks
if( !Timer ) return ;
@@
-142,9
+132,10
@@
void Time_ScheduleTimer(tTimer *Timer, int Delta)
// Add into list (sorted)
SHORTLOCK(&gTimers_ListLock);
// Mutex_Release( &Timer->Lock ); // Prevent deadlocks
// 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( p
rev_next = &gTimers, t = gTimers; t; prev_next = &t->Nex
t, 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");
if( t == Timer )
{
LOG("Double schedule - increasing delta");
@@
-155,9
+146,9
@@
void Time_ScheduleTimer(tTimer *Timer, int Delta)
if( t->FiresAfter > Timer->FiresAfter ) break;
}
Timer->Next = t;
if( t->FiresAfter > Timer->FiresAfter ) break;
}
Timer->Next = t;
-
p->N
ext = Timer;
+
*prev_n
ext = Timer;
Timer->bActive = 1;
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);
}
SHORTREL(&gTimers_ListLock);
}
@@
-166,17
+157,19
@@
void Time_ScheduleTimer(tTimer *Timer, int Delta)
*/
void Time_RemoveTimer(tTimer *Timer)
{
*/
void Time_RemoveTimer(tTimer *Timer)
{
- tTimer *t, *p;
+ tTimer *t;
+ tTimer **prev_next;
if( !Timer ) return ;
SHORTLOCK(&gTimers_ListLock);
if( !Timer ) return ;
SHORTLOCK(&gTimers_ListLock);
- for( p
= (tTimer*)&gTimers, t = gTimers; t; p =
t, t = t->Next )
+ for( p
rev_next = &gTimers, t = gTimers; t; prev_next = &t->Nex
t, t = t->Next )
{
{
- ASSERT( p != t ); ASSERT( CheckMem(t, sizeof(tTimer)) );
+ ASSERT( prev_next != &t->Next );
+ ASSERT( CheckMem(t, sizeof(tTimer)) );
if( t == Timer )
{
if( t == Timer )
{
-
p->N
ext = t->Next;
+
*prev_n
ext = t->Next;
break ;
}
}
break ;
}
}
@@
-214,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;
Timer->Argument = Argument;
// memset( &Timer->Lock, 0, sizeof(Timer->Lock) );
Timer->bActive = 0;
+ LOG("Initialised timer %p (cb=%p,arg=%p)", Timer, Callback, Argument);
}
/**
}
/**
@@
-240,11
+234,11
@@
void Time_FreeTimer(tTimer *Timer)
*/
void Time_Delay(int Delay)
{
*/
void Time_Delay(int Delay)
{
- tTimer *t;
- t = Time_AllocateTimer(NULL, NULL);
+ LOG("(%i)", Delay);
+ tTimer *t = &Proc_GetCurThread()->ThreadTimer;
+ Time_InitTimer(t, NULL, NULL);
Time_ScheduleTimer(t, Delay);
Threads_WaitEvents(THREAD_EVENT_TIMER);
Time_ScheduleTimer(t, Delay);
Threads_WaitEvents(THREAD_EVENT_TIMER);
- Time_FreeTimer(t);
}
// === EXPORTS ===
}
// === EXPORTS ===
UCC
git Repository :: git.ucc.asn.au