当前位置: 首页>>代码示例>>C++>>正文


C++ AtomicCounter类代码示例

本文整理汇总了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;
}
开发者ID:axelexic,项目名称:NTL,代码行数:21,代码来源:fileio.c

示例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);
}
开发者ID:austinsc,项目名称:Poco,代码行数:40,代码来源:CoreTest.cpp

示例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;
}
开发者ID:95krasovsky,项目名称:SecretSharingSchemes,代码行数:22,代码来源:fileio.c

示例4:

AtomicCounter::AtomicCounter(const AtomicCounter& counter):
    _counter(counter.value())
{
}
开发者ID:liyustar,项目名称:liblyx,代码行数:4,代码来源:lyxAtomicCounter.cpp

示例5:

AtomicCounter::AtomicCounter(const AtomicCounter& counter)
{
	_counter.value = counter.value();
}
开发者ID:HSOFEUP,项目名称:MOOS-IvP-releases,代码行数:4,代码来源:AtomicCounter.cpp

示例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;
}
开发者ID:sjburt,项目名称:fractals,代码行数:27,代码来源:main.cpp

示例7: init

void DFUTransportUSB::init()
{
	if(init_counter.inc() == 1)
	{
		map = new CMapX<CStringX, const TCHAR *, CStringX, const TCHAR *>;
		lockMap = new CriticalSection;
	}
}
开发者ID:philiplin4sp,项目名称:production-test-tool,代码行数:8,代码来源:DFUTransportUSB.cpp

示例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();
}
开发者ID:philiplin4sp,项目名称:production-test-tool,代码行数:9,代码来源:DFUFileInfoCache.cpp

示例9: deinit

void DFUTransportUSB::deinit()
{
	if(init_counter.dec() == 0)
	{
		delete map;
		map = NULL;
		delete lockMap;
		lockMap = NULL;
	}
}
开发者ID:philiplin4sp,项目名称:production-test-tool,代码行数:10,代码来源:DFUTransportUSB.cpp

示例10: deinit

void DFUFileInfoCache::deinit()
{
	DFUFileCache::deinit();
	if(init_counter.dec() == 0)
	{
		delete map;
		map = NULL;
		delete lockMap;
		lockMap = NULL;
	}
}
开发者ID:philiplin4sp,项目名称:production-test-tool,代码行数:11,代码来源:DFUFileInfoCache.cpp

示例11: reset

 void reset() {
   success = 0;
   failure = 0;
   cnt.reset();
 }
开发者ID:simon-rock,项目名称:mcrouter,代码行数:5,代码来源:awriter_test.cpp


注:本文中的AtomicCounter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。