本文整理汇总了C++中AtomicCounter类的典型用法代码示例。如果您正苦于以下问题:C++ AtomicCounter类的具体用法?C++ AtomicCounter怎么用?C++ AtomicCounter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AtomicCounter类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UniqueID
const string& UniqueID()
{
static AtomicCounter cnt; // a GLOBAL counter
NTL_THREAD_LOCAL static string ID;
NTL_THREAD_LOCAL static bool initialized = false;
NTL_THREAD_LOCAL static unsigned long local_cnt = cnt.inc();
NTL_THREAD_LOCAL static unsigned long local_time = time(0);
NTL_THREAD_LOCAL static unsigned long local_clock = clock();
if (!initialized) {
stringstream ss;
ss << local_cnt << "-" << local_time << "-"
<< local_clock << "-" << GetPID() << "-" << CurrentThreadID();
ID = ss.str();
initialized = true;
}
return ID;
}
示例2: assert
void CoreTest::testAtomicCounter()
{
AtomicCounter ac;
assert (ac.value() == 0);
assert (ac++ == 0);
assert (ac-- == 1);
assert (++ac == 1);
assert (--ac == 0);
ac = 2;
assert (ac.value() == 2);
ac = 0;
assert (ac.value() == 0);
AtomicCounter ac2(2);
assert (ac2.value() == 2);
ACTRunnable act(ac);
Thread t1;
Thread t2;
Thread t3;
Thread t4;
Thread t5;
t1.start(act);
t2.start(act);
t3.start(act);
t4.start(act);
t5.start(act);
t1.join();
t2.join();
t3.join();
t4.join();
t5.join();
assert (ac.value() == 0);
}
示例3: UniqueID
const string& UniqueID()
{
static AtomicCounter cnt; // a GLOBAL counter
NTL_TLS_LOCAL(string, ID);
NTL_TLS_LOCAL_INIT(bool, initialized, (false));
NTL_TLS_LOCAL_INIT(unsigned long, local_cnt, (cnt.inc()));
NTL_TLS_LOCAL_INIT(unsigned long, local_time, (time(0)));
NTL_TLS_LOCAL_INIT(unsigned long, local_clock, (clock()));
if (!initialized) {
stringstream ss;
ss << local_cnt << "-" << local_time << "-"
<< local_clock << "-" << GetPID() << "-" << CurrentThreadID();
ID = ss.str();
initialized = true;
}
return ID;
}
示例4:
AtomicCounter::AtomicCounter(const AtomicCounter& counter):
_counter(counter.value())
{
}
示例5:
AtomicCounter::AtomicCounter(const AtomicCounter& counter)
{
_counter.value = counter.value();
}
示例6: render
int RenderContext::render(void) {
tm.Start();
glm::uvec3 counters = glm::uvec3(0);
ac.reset();
glfwGetCursorPos(window, &pos_x, &pos_y);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mb.render(iter, aspect_ratio, cx, cy, cur_scale);
text.print(hud, 10, 50, screen_width, screen_height);
counters = ac.read();
tm.Stop();
float time = tm.Report();
glfwSwapBuffers(window);
glfwPollEvents();
float mod = glm::clamp(16000.0f / time, .1f, 2.0f);
iter = glm::clamp(int(iter * mod), 10, 50000) ;
// iter = 100;
snprintf(hud, sizeof(hud), "%5.2fms, %5E, %5i,\n%5.3E, %6f, %6f \n",
time/1000, double(counters[0]), iter, cur_scale, cx, cy);
// printf("%s\n", hud);
return 0;
}
示例7: init
void DFUTransportUSB::init()
{
if(init_counter.inc() == 1)
{
map = new CMapX<CStringX, const TCHAR *, CStringX, const TCHAR *>;
lockMap = new CriticalSection;
}
}
示例8: init
void DFUFileInfoCache::init()
{
if(init_counter.inc() == 1)
{
map = new CMapX<CStringX, const TCHAR *, DFUFileInfoCache::Cache, DFUFileInfoCache::Cache &>;
lockMap = new CriticalSection;
}
DFUFileCache::init();
}
示例9: deinit
void DFUTransportUSB::deinit()
{
if(init_counter.dec() == 0)
{
delete map;
map = NULL;
delete lockMap;
lockMap = NULL;
}
}
示例10: deinit
void DFUFileInfoCache::deinit()
{
DFUFileCache::deinit();
if(init_counter.dec() == 0)
{
delete map;
map = NULL;
delete lockMap;
lockMap = NULL;
}
}
示例11: reset
void reset() {
success = 0;
failure = 0;
cnt.reset();
}