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 - Rename _EXECUTE to _EXEC (VFS perm flag)
[tpg/acess2.git]
/
KernelLand
/
Kernel
/
time.c
diff --git
a/KernelLand/Kernel/time.c
b/KernelLand/Kernel/time.c
index
cf3370a
..
a6ccd8b
100644
(file)
--- a/
KernelLand/Kernel/time.c
+++ b/
KernelLand/Kernel/time.c
@@
-1,5
+1,5
@@
/*
/*
- * Acess
2
+ * Acess
2 Kernel
* - By John Hodge (thePowersGang)
*
* Timer Code
* - By John Hodge (thePowersGang)
*
* Timer Code
@@
-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);
@@
-49,6
+41,7
@@
tShortSpinlock gTimers_ListLock;
void Timer_CallbackThread(void *Unused)
{
Threads_SetName("Timer Callback Thread");
void Timer_CallbackThread(void *Unused)
{
Threads_SetName("Timer Callback Thread");
+ Workqueue_Init(&gTimers_CallbackQueue, "Timer Callbacks", offsetof(tTimer, Next));
for(;;)
{
for(;;)
{
@@
-81,20
+74,20
@@
void Timer_CallbackThread(void *Unused)
*/
void Timer_CallTimers()
{
*/
void Timer_CallTimers()
{
+ // Tick the random number generator every time timers are checked
+ rand();
+
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 {
@@
-124,7
+117,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 ;
@@
-141,9
+135,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");
@@
-154,9
+149,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);
}
@@
-165,17
+160,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 ;
}
}
@@
-213,6
+210,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);
}
/**
}
/**
@@
-239,11
+237,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