}
}
-static uint32
-fastrand1(void)
-{
- static uint32 x = 0x49f6428aUL;
-
- x += x;
- if(x & 0x80000000L)
- x ^= 0x88888eefUL;
- return x;
-}
-
static uint32
fastrandn(uint32 n)
{
if(n <= 1)
return 0;
- r = fastrand1();
+ r = runtime·fastrand1();
if(r < (1ULL<<31)-n) // avoid computing max in common case
return r%n;
max = (1ULL<<31)/n * n;
while(r >= max)
- r = fastrand1();
+ r = runtime·fastrand1();
return r%n;
}
extern volatile int32 runtime·MemProfileRate;
-// Same algorithm from chan.c, but a different
-// instance of the static uint32 x.
-// Not protected by a lock - let the threads use
-// the same random number if they like.
-static uint32
-fastrand1(void)
-{
- static uint32 x = 0x49f6428aUL;
-
- x += x;
- if(x & 0x80000000L)
- x ^= 0x88888eefUL;
- return x;
-}
-
// Allocate an object of at least size bytes.
// Small objects are allocated from the per-thread cache's free lists.
// Large objects (> 32 kB) are allocated straight from the heap.
// pick next profile time
if(rate > 0x3fffffff) // make 2*rate not overflow
rate = 0x3fffffff;
- m->mcache->next_sample = fastrand1() % (2*rate);
+ m->mcache->next_sample = runtime·fastrand1() % (2*rate);
profile:
runtime·setblockspecial(v);
runtime·MProf_Malloc(v, size);
runtime·allm = m;
m->nomemprof++;
+ m->fastrand = 0x49f6428aUL + m->id;
runtime·mallocinit();
runtime·goargs();
m->alllink = runtime·allm;
runtime·allm = m;
m->id = runtime·sched.mcount++;
+ m->fastrand = 0x49f6428aUL + m->id;
if(runtime·iscgo) {
CgoThreadStart ts;
int32 waitnextg;
int32 dying;
int32 profilehz;
+ uint32 fastrand;
Note havenextg;
G* nextg;
M* alllink; // on allm
void* runtime·getcallersp(void*);
int32 runtime·mcount(void);
void runtime·mcall(void(*)(G*));
+uint32 runtime·fastrand1(void);
void runtime·exit(int32);
void runtime·breakpoint(void);