From: John Hodge Date: Wed, 23 Sep 2009 05:01:08 +0000 (+0800) Subject: Moved rand from arch/proc to lib.c and changed it to a LCG X-Git-Tag: rel0.06~532 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=ef2ef0b76dca5bd5ee3b80fb7f831f89fc81f80d;p=tpg%2Facess2.git Moved rand from arch/proc to lib.c and changed it to a LCG --- diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index d7af3e3d..0f9f449f 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -11,7 +11,6 @@ #endif // === CONSTANTS === -#define RANDOM_SEED 0xACE55052 #define SWITCH_MAGIC 0xFFFACE55 // There is no code in this area #define DEFAULT_QUANTUM 10 #define DEFAULT_TICKETS 5 @@ -345,6 +344,7 @@ void Proc_SetThreadName(char *NewName) /** * \fn Uint Proc_MakeUserStack() + * \brief Creates a new user stack */ Uint Proc_MakeUserStack() { @@ -684,6 +684,7 @@ static tThread *Proc_int_GetPrevThread(tThread **List, tThread *Thread) /** * \fn void Proc_DumpThreads() + * \brief Dums a list of currently running threads */ void Proc_DumpThreads() { @@ -707,7 +708,7 @@ void Proc_DumpThreads() /** * \fn void Proc_Scheduler(int CPU) - * \brief Swap current task + * \brief Swap current thread and clears dead threads */ void Proc_Scheduler(int CPU) { @@ -819,18 +820,3 @@ int Proc_GetGID() { return gCurrentThread->GID; } - -/** - * \fn Uint rand() - * \brief Pseudo random number generator - * \note Unknown effectiveness (made up on the spot) - */ -Uint rand() -{ - static Uint randomState = RANDOM_SEED; - Uint ret = randomState; - int roll = randomState & 31; - randomState = (randomState << roll) | (randomState >> (32-roll)); - randomState ^= 0x9A3C5E78; - return ret; -} diff --git a/Kernel/lib.c b/Kernel/lib.c index c8a0e9f1..0dbb9b96 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -5,6 +5,9 @@ #include // === CONSTANTS === +#define RANDOM_SEED 0xACE55052 +#define RANDOM_A 0x12231ADE +#define RANDOM_C 0x1BADBEEF // Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec const short DAYS_BEFORE[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; #define UNIX_TO_2K ((30*365*3600*24) + (7*3600*24)) //Normal years + leap years @@ -293,5 +296,25 @@ Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year) return stamp * 1000; } +/** + * \fn Uint rand() + * \brief Pseudo random number generator + * \note Unknown effectiveness (made up on the spot) + */ +Uint rand() +{ + #if 0 + static Uint randomState = RANDOM_SEED; + Uint ret = randomState; + int roll = randomState & 31; + randomState = (randomState << roll) | (randomState >> (32-roll)); + randomState ^= 0x9A3C5E78; + return ret; + #else + static Uint randomState = RANDOM_SEED; + return randomState = (RANDOM_A*randomState + RANDOM_C) & 0xFFFFFFFF; + #endif +} + EXPORT(timestamp); EXPORT(ReadUTF8);