Moved rand from arch/proc to lib.c and changed it to a LCG
authorJohn Hodge <[email protected]>
Wed, 23 Sep 2009 05:01:08 +0000 (13:01 +0800)
committerJohn Hodge <[email protected]>
Wed, 23 Sep 2009 05:01:08 +0000 (13:01 +0800)
Kernel/arch/x86/proc.c
Kernel/lib.c

index d7af3e3..0f9f449 100644 (file)
@@ -11,7 +11,6 @@
 #endif
 
 // === CONSTANTS ===
 #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
 #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()
 
 /**
  * \fn Uint Proc_MakeUserStack()
+ * \brief Creates a new user stack
  */
 Uint Proc_MakeUserStack()
 {
  */
 Uint Proc_MakeUserStack()
 {
@@ -684,6 +684,7 @@ static tThread *Proc_int_GetPrevThread(tThread **List, tThread *Thread)
 
 /**
  * \fn void Proc_DumpThreads()
 
 /**
  * \fn void Proc_DumpThreads()
+ * \brief Dums a list of currently running threads
  */
 void Proc_DumpThreads()
 {
  */
 void Proc_DumpThreads()
 {
@@ -707,7 +708,7 @@ void Proc_DumpThreads()
 
 /**
  * \fn void Proc_Scheduler(int CPU)
 
 /**
  * \fn void Proc_Scheduler(int CPU)
- * \brief Swap current task
+ * \brief Swap current thread and clears dead threads
  */
 void Proc_Scheduler(int CPU)
 {
  */
 void Proc_Scheduler(int CPU)
 {
@@ -819,18 +820,3 @@ int Proc_GetGID()
 {
        return gCurrentThread->GID;
 }
 {
        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;
-}
index c8a0e9f..0dbb9b9 100644 (file)
@@ -5,6 +5,9 @@
 #include <common.h>
 
 // === CONSTANTS ===
 #include <common.h>
 
 // === 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
 //                          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;
 }
 
        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);
 EXPORT(timestamp);
 EXPORT(ReadUTF8);

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