void workerThread() { bool r = options["r"].trueValue(); bool w = options["w"].trueValue(); cout << "read:" << r << " write:" << w << endl; long long su = options["sleepMicros"].numberLong(); Aligned a; while( 1 ) { unsigned long long rofs = (rrand() * PG) % len; unsigned long long wofs = (rrand() * PG) % len; const unsigned P = PG/1024; if( mmf ) { if( r ) { for( unsigned p = P; p <= recSizeKB; p += P ) { if( rofs < len ) dummy += mmf[rofs]; rofs += PG; } iops.fetchAndAdd(1); } if( w ) { for( unsigned p = P; p <= recSizeKB; p += P ) { if( wofs < len ) mmf[wofs] = 3; wofs += PG; } iops.fetchAndAdd(1); } } else { if( r ) { lf->readAt(rofs, a.addr(), recSizeKB * 1024); iops.fetchAndAdd(1); } if( w ) { lf->writeAt(wofs, a.addr(), recSizeKB * 1024); iops.fetchAndAdd(1); } } long long micros = su / nThreadsRunning; if( micros ) { sleepmicros(micros); } } }
void OID::init() { static AtomicUInt32 inc( static_cast<unsigned>( scoped_ptr<SecureRandom>(SecureRandom::create())->nextInt64())); { unsigned t = (unsigned) time(0); unsigned char *T = (unsigned char *) &t; _time[0] = T[3]; // big endian order because we use memcmp() to compare OID's _time[1] = T[2]; _time[2] = T[1]; _time[3] = T[0]; } _machineAndPid = ourMachineAndPid; { int new_inc = inc.fetchAndAdd(1); unsigned char *T = (unsigned char *) &new_inc; _inc[0] = T[2]; _inc[1] = T[1]; _inc[2] = T[0]; } }
void increment(unsigned n) { for (unsigned i = 0; i < n; i++) { counter.fetchAndAdd(1); } }