util: style fixes
This commit is contained in:
@@ -16,8 +16,8 @@
|
|||||||
#define MAX_FAST_RANDOM_VALUE 0x7fff
|
#define MAX_FAST_RANDOM_VALUE 0x7fff
|
||||||
#define MAX_RANDOM_VALUE 0x7fffffffu
|
#define MAX_RANDOM_VALUE 0x7fffffffu
|
||||||
|
|
||||||
const int kFastRandomShift = 15;
|
static const int kFastRandomShift = 15;
|
||||||
const int kRandomShift = 31;
|
static const int kRandomShift = 31;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
|
|
||||||
static uint32 fast_last = 0;
|
static uint32 sFastLast = 0;
|
||||||
static uint32 last = 0;
|
static uint32 sLast = 0;
|
||||||
|
|
||||||
// In the following functions there are race conditions when many threads
|
// In the following functions there are race conditions when many threads
|
||||||
// attempt to update static variable last. However, since such conflicts
|
// attempt to update static variable last. However, since such conflicts
|
||||||
@@ -24,11 +24,11 @@ static uint32 last = 0;
|
|||||||
unsigned int
|
unsigned int
|
||||||
fast_random_value()
|
fast_random_value()
|
||||||
{
|
{
|
||||||
if (fast_last == 0)
|
if (sFastLast == 0)
|
||||||
fast_last = system_time();
|
sFastLast = system_time();
|
||||||
|
|
||||||
uint32 random = fast_last * 1103515245 + 12345;
|
uint32 random = sFastLast * 1103515245 + 12345;
|
||||||
fast_last = random;
|
sFastLast = random;
|
||||||
return (random >> 16) & 0x7fff;
|
return (random >> 16) & 0x7fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,16 +39,16 @@ fast_random_value()
|
|||||||
unsigned int
|
unsigned int
|
||||||
random_value()
|
random_value()
|
||||||
{
|
{
|
||||||
if (last == 0)
|
if (sLast == 0)
|
||||||
last = system_time();
|
sLast = system_time();
|
||||||
|
|
||||||
uint32 hi = last / 127773;
|
uint32 hi = sLast / 127773;
|
||||||
uint32 lo = last % 127773;
|
uint32 lo = sLast % 127773;
|
||||||
|
|
||||||
int32 random = 16807 * lo - 2836 * hi;
|
int32 random = 16807 * lo - 2836 * hi;
|
||||||
if (random <= 0)
|
if (random <= 0)
|
||||||
random += MAX_RANDOM_VALUE;
|
random += MAX_RANDOM_VALUE;
|
||||||
last = random;
|
sLast = random;
|
||||||
return random % (MAX_RANDOM_VALUE + 1);
|
return random % (MAX_RANDOM_VALUE + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user