本文整理汇总了C++中AtomicUInt32::fetchAndAdd方法的典型用法代码示例。如果您正苦于以下问题:C++ AtomicUInt32::fetchAndAdd方法的具体用法?C++ AtomicUInt32::fetchAndAdd怎么用?C++ AtomicUInt32::fetchAndAdd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AtomicUInt32
的用法示例。
在下文中一共展示了AtomicUInt32::fetchAndAdd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: workerThread
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);
}
}
}
示例2: init
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];
}
}
示例3: increment
void increment(unsigned n) {
for (unsigned i = 0; i < n; i++) {
counter.fetchAndAdd(1);
}
}