From 03522f70735d2db32e52e2fd5388439570ab0d0f Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 23 Aug 2012 13:30:03 +0800 Subject: [PATCH] Kernel - Added a per-thread timer object to reduce malloc use --- KernelLand/Kernel/include/threads_int.h | 9 ++++++++- KernelLand/Kernel/include/timers_int.h | 25 +++++++++++++++++++++++++ KernelLand/Kernel/time.c | 17 ++++------------- 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 KernelLand/Kernel/include/timers_int.h diff --git a/KernelLand/Kernel/include/threads_int.h b/KernelLand/Kernel/include/threads_int.h index 2f15a729..881db4ab 100644 --- a/KernelLand/Kernel/include/threads_int.h +++ b/KernelLand/Kernel/include/threads_int.h @@ -1,5 +1,9 @@ /* - * Internal Threading header + * Acess2 Kernel + * - By John Hodge (thePowersGang) + * + * include/threads_int.h + * - Internal Threading header * - Only for use by stuff that needs access to the thread type. */ #ifndef _THREADS_INT_H_ @@ -7,6 +11,7 @@ #include #include +#include typedef struct sProcess tProcess; @@ -92,6 +97,8 @@ struct sThread // --- event.c Uint32 EventState; + // --- timer.c + tTimer ThreadTimer; }; diff --git a/KernelLand/Kernel/include/timers_int.h b/KernelLand/Kernel/include/timers_int.h new file mode 100644 index 00000000..85a52ec7 --- /dev/null +++ b/KernelLand/Kernel/include/timers_int.h @@ -0,0 +1,25 @@ +/* + * Acess2 Kernel + * - By John Hodge (thePowersGang) + * + * include/timers_int.h + * - Timer internal header + * - Only for use by code that needs access to timer internals + */ +#ifndef _KERNEL__TIMERS_INT_H_ +#define _KERNEL__TIMERS_INT_H_ + +#include + +// === TYPEDEFS === +struct sTimer { + tTimer *Next; + Sint64 FiresAfter; + void (*Callback)(void*); + void *Argument; +// tMutex Lock; + BOOL bActive; +}; + +#endif + diff --git a/KernelLand/Kernel/time.c b/KernelLand/Kernel/time.c index d8c29245..449afcd9 100644 --- a/KernelLand/Kernel/time.c +++ b/KernelLand/Kernel/time.c @@ -8,19 +8,11 @@ #define DEBUG 0 #include #include +#include #include #include // Proc_GetCurThread #include - -// === TYPEDEFS === -struct sTimer { - tTimer *Next; - Sint64 FiresAfter; - void (*Callback)(void*); - void *Argument; -// tMutex Lock; - BOOL bActive; -}; +#include // Used to get thread timer // === PROTOTYPES === void Timer_CallbackThread(void *Unused); @@ -240,11 +232,10 @@ void Time_FreeTimer(tTimer *Timer) */ void Time_Delay(int Delay) { - tTimer *t; - t = Time_AllocateTimer(NULL, NULL); + tTimer *t = &Proc_GetCurThread()->ThreadTimer; + Time_InitTimer(t, NULL, NULL); Time_ScheduleTimer(t, Delay); Threads_WaitEvents(THREAD_EVENT_TIMER); - Time_FreeTimer(t); } // === EXPORTS === -- 2.20.1