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


C++ Atomic类代码示例

本文整理汇总了C++中Atomic的典型用法代码示例。如果您正苦于以下问题:C++ Atomic类的具体用法?C++ Atomic怎么用?C++ Atomic使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Atomic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

void XAsset::createD3HierarchyClasses(Clump* clump, D3DXFRAME* frame)
{
    Frame* f = static_cast<Frame*>( frame );
    while( f->pMeshContainer )
    {
        Mesh* mesh = static_cast<Mesh*>( f->pMeshContainer );
        
        const char* geometryName = mesh->Name;
        if( !geometryName ) geometryName = "NamelessGeometry";
        Geometry* geometry = new Geometry( mesh, geometryName );

        Atomic* atomic = new Atomic;
        atomic->setGeometry( geometry );
        atomic->setFrame( f );

        clump->add( atomic );

        f->pMeshContainer = f->pMeshContainer->pNextMeshContainer;
    }

    if( f->pFrameFirstChild ) 
    {
        static_cast<Frame*>( f->pFrameFirstChild )->pParentFrame = f;
        createD3HierarchyClasses( clump, f->pFrameFirstChild );
    }

    if( f->pFrameSibling ) 
    {
        static_cast<Frame*>( f->pFrameSibling )->pParentFrame = f->pParentFrame;
        createD3HierarchyClasses( clump, f->pFrameSibling );
    }
}
开发者ID:AndreMeijer86,项目名称:base-pro-edition,代码行数:32,代码来源:xasset.cpp

示例2: setAtomicWorldCB

engine::IAtomic* BSP::setAtomicWorldCB(engine::IAtomic* atomic, void* data)
{
    Atomic* a = dynamic_cast<Atomic*>( atomic );
    a->_bsp = data;
    a->onUpdate();
    return atomic;
}
开发者ID:cheinkn,项目名称:basextreme,代码行数:7,代码来源:bsp.cpp

示例3: BOOST_AUTO_TEST_CASE_TEMPLATE

BOOST_AUTO_TEST_CASE_TEMPLATE(SwapTest, T, AtomicSwapTypes)
{
    Atomic<T> value = 102;
    T const old = value.Swap(T(123));
    BOOST_CHECK_EQUAL(old, T(102));
    BOOST_CHECK_EQUAL(value, T(123));
}
开发者ID:ancapdev,项目名称:crunch.concurrency,代码行数:7,代码来源:atomic_tests.cpp

示例4: DiffOrder

void
Triangle_Processor::Divide(unsigned int N, Stack<AtomicRegion>&  Offspring)
  {
  Stack<Triangle> Parts;  
  Vector<unsigned int> DiffOrder(Diffs.Size());
  real NewVolume;
  
  switch(N)
    {
    case 2: 
    {    
    NewVolume = Geometry().Volume()/2;

    TheRule->ComputeDiffs(LocalIntegrand(),Geometry(),Diffs);

    // Sort the differences in descending order.
    for (unsigned int ik=0 ; ik<=2 ; ik++)  { DiffOrder[ik] = ik; }
    for (unsigned int i=0 ; i<=1 ; i++)  
      {
      for (unsigned int k=i+1 ; k<=2 ; k++)
         if (Diffs[DiffOrder[k]]>Diffs[DiffOrder[i]])
            {
            unsigned int h = DiffOrder[i];
            DiffOrder[i] = DiffOrder[k];
            DiffOrder[k] = h;
            }
      }
    TheDivisor2->Apply (Geometry(),Parts,DiffOrder);
    break;
    }
  
    case 4:
    {
    NewVolume = Geometry().Volume()/4;
    TheDivisor4->Apply (Geometry(),Parts,DiffOrder);
    break;
    }
  
    default:
      {
        NewVolume = Geometry().Volume()/N; 
        Error(True,"This kind of subdivision is not implemented");
      }
    }
  
  
  for (unsigned int i =0;i<N;i++)
    {
    Triangle* g = Parts.Pop();
    g->Volume(NewVolume);
    Processor<Triangle>* p = Descendant();
    Atomic<Triangle>* a = new Atomic<Triangle>(g,p);
    a->LocalIntegrand(&LocalIntegrand());
    Offspring.Push(a);
    };
    
  return;

  }
开发者ID:kwrobert,项目名称:ResearchCode,代码行数:59,代码来源:T2prc.cpp

示例5: renderAtomic

void ObjectRenderer::renderInstance(InstanceObject* instance,
                                    RenderList& outList) {
    const auto& atomic = instance->getAtomic();
    if (!atomic) {
        return;
    }

    // Only draw visible objects
    if (!instance->getVisible()) {
        return;
    }

    auto modelinfo = instance->getModelInfo<SimpleModelInfo>();

    // Handles times provided by TOBJ data
    const auto currentHour = m_world->getHour();
    if (modelinfo->timeOff < modelinfo->timeOn) {
        if (currentHour >= modelinfo->timeOff &&
            currentHour < modelinfo->timeOn)
            return;
    } else {
        if (currentHour >= modelinfo->timeOff ||
            currentHour < modelinfo->timeOn)
            return;
    }

    float mindist = glm::length(instance->getPosition() - m_camera.position) /
                    kDrawDistanceFactor;

    if (mindist > modelinfo->getLargestLodDistance()) {
        culled++;
        return;
    }

    if (modelinfo->isBigBuilding() &&
        mindist < modelinfo->getNearLodDistance() &&
        mindist < kMagicLODDistance) {
        auto related = modelinfo->related();
        if (!related || related->isLoaded()) {
            culled++;
            return;
        }
    }

    Atomic* distanceatomic =
        modelinfo->getDistanceAtomic(mindist / kDrawDistanceFactor);
    if (!distanceatomic) {
        return;
    }

    if (atomic->getGeometry() != distanceatomic->getGeometry()) {
        atomic->setGeometry(distanceatomic->getGeometry());
    }

    // Render the atomic the instance thinks it should be
    renderAtomic(atomic.get(), glm::mat4(), instance, outList);
}
开发者ID:aldoxtor,项目名称:openrw,代码行数:57,代码来源:ObjectRenderer.cpp

示例6: mAllocSize

SharedMemory::SharedMemory()
  : mAllocSize(0)
  , mMappedSize(0)
{
  static Atomic<uint32_t> registered;
  if (registered.compareExchange(0, 1)) {
    RegisterStrongMemoryReporter(new ShmemAllocatedReporter());
    RegisterStrongMemoryReporter(new ShmemMappedReporter());
  }
}
开发者ID:Gabuzo,项目名称:mozilla-central,代码行数:10,代码来源:SharedMemory.cpp

示例7: mAllocSize

SharedMemory::SharedMemory()
  : mAllocSize(0)
  , mMappedSize(0)
{
  MOZ_COUNT_CTOR(SharedMemory);
  static Atomic<bool> registered;
  if (registered.compareExchange(false, true)) {
    RegisterStrongMemoryReporter(new ShmemReporter());
  }
}
开发者ID:chardis,项目名称:gecko-dev,代码行数:10,代码来源:SharedMemory.cpp

示例8: __atomic_compare_exchange_n

inline bool Atomic<T>::cswap ( const Atomic<T> &oldval, const Atomic<T> &newval )
{
#ifdef HAVE_NEW_GCC_ATOMIC_OPS
   // FIXME: The atomics passed are const
   T* oldv = const_cast<T*>(&oldval._value);
   T* newv = const_cast<T*>(&newval._value);
   return __atomic_compare_exchange_n( &_value, oldv, newv,
         /* weak */ false, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE );
#else
   return __sync_bool_compare_and_swap ( &_value, oldval.value(), newval.value() );
#endif
}
开发者ID:osubasi,项目名称:CRC-in-Nanox,代码行数:12,代码来源:atomic.hpp

示例9: switch

void Census::visit(const std::shared_ptr<Instruction> &instruction) {
	instructions_.push_back(instruction.get());
	unique_ = false;

	switch (instruction->mnemonic()) {
		case Instruction::READ: {
			Read *read = instruction->as<Read>();
			visit(read->reg());
			visit(read->address());
			spaces_.push_back(read->space());
			break;
		}
		case Instruction::WRITE: {
			Write *write = instruction->as<Write>();
			visit(write->value());
			visit(write->address());
			spaces_.push_back(write->space());
			break;
		}
		case Instruction::MFENCE: {
			break;
		}
		case Instruction::LOCAL: {
			Local *local = instruction->as<Local>();
			visit(local->reg());
			visit(local->value());
			break;
		}
		case Instruction::CONDITION: {
			Condition *condition = instruction->as<Condition>();
			visit(condition->expression());
			break;
		}
		case Instruction::ATOMIC: {
			Atomic *atomic = instruction->as<Atomic>();
			for (const auto &instr : atomic->instructions()) {
				visit(instr);
			}
			break;
		}
		case Instruction::NOOP: /* FALLTHROUGH */
		case Instruction::LOCK: /* FALLTHROUGH */
		case Instruction::UNLOCK:
			break;
		default: {
			assert(!"NEVER REACHED");
		}
	}
}
开发者ID:yegord,项目名称:trencher,代码行数:49,代码来源:Census.cpp

示例10: testPerfAddAndFetch

double testPerfAddAndFetch()
{
    const std::size_t iters(30000);
    StopWatch stopWatch;
    double total(0);

    for(std::size_t iter = 0; iter != iters; ++iter)
    {
        Atomic<T> atomic;
        stopWatch.start();
        for(std::size_t count = 0; count != testing::STANDARD_SPEED_COUNT; ++count) {
            atomic.addAndFetch(1);
        }
        stopWatch.stop();
        total += getTimevalAsMicros(stopWatch.elapsed());
        stopWatch.reset();
    }
    return testing::calcNanosPer(total, iters);
}
开发者ID:staticimport,项目名称:promotelib,代码行数:19,代码来源:AtomicTest.cpp

示例11: testPerfFetch

double testPerfFetch()
{
    const std::size_t iters(30000);
    StopWatch stopWatch;
    double total(0);

    int foo(0);
    for(std::size_t iter = 0; iter != iters; ++iter)
    {
        Atomic<T> atomic;
        stopWatch.start();
        for(std::size_t count = 0; count != testing::STANDARD_SPEED_COUNT; ++count) {
            foo += atomic.fetch(); // To ensure fetch is actually called
        }
        stopWatch.stop();
        total += getTimevalAsMicros(stopWatch.elapsed());
        stopWatch.reset();
    }
    return testing::calcNanosPer(total, iters);
}
开发者ID:staticimport,项目名称:promotelib,代码行数:20,代码来源:AtomicTest.cpp

示例12: testPerfCompareAndSwap

double testPerfCompareAndSwap(bool success)
{
    const std::size_t iters(30000);
    StopWatch stopWatch;
    double total(0);
    const T compare = success ? 0 : 1;

    for(std::size_t iter = 0; iter != iters; ++iter)
    {
        Atomic<T> atomic;
        stopWatch.start();
        for(std::size_t count = 0; count != testing::STANDARD_SPEED_COUNT; ++count) {
            atomic.compareAndSwap(compare, compare);
        }
        stopWatch.stop();
        total += getTimevalAsMicros(stopWatch.elapsed());
        stopWatch.reset();
    }
    return testing::calcNanosPer(total, iters);
}
开发者ID:staticimport,项目名称:promotelib,代码行数:20,代码来源:AtomicTest.cpp

示例13: queryInterface


//.........这里部分代码省略.........
                if( importData->prelights )
                {
                    geometry->getPrelights(0)[i] = wrap( importData->prelights[i] );
                }
            }
            for( i=0; i<importData->numTriangles; i++ )
            {
                /*
                geometry->getTriangles()[i].set(
                    importData->triangles[i].vertexId[0],
					importData->triangles[i].vertexId[2],
					importData->triangles[i].vertexId[1],					
                    importData->triangles[i].materialId
                );
                */
                geometry->getTriangles()[i].set(
                    importData->triangles[i].vertexId[0],
                    importData->triangles[i].vertexId[1],
					importData->triangles[i].vertexId[2],					
                    importData->triangles[i].materialId
                );
            }
            for( i=0; i<importData->numMaterials; i++ )
            {
                ShaderI shaderI = _shaders.find( importData->materials[i] );
                assert( shaderI != _shaders.end() );
                geometry->setShader( i, shaderI->second );
            }
            geometry->instance();
            _geometries.insert( GeometryT( importData->id, geometry ) );
            iImport->release( importData );
        }
        break;
    case import::itAtomic:
        {
            import::ImportAtomic* importData = iImportStream->importAtomic();
            Atomic* atomic = new Atomic;
            FrameI frameI = _frames.find( importData->frameId );
            assert( frameI != _frames.end() );
            atomic->setFrame( frameI->second );
            GeometryI geometryI = _geometries.find( importData->geometryId );
            assert( geometryI != _geometries.end() );
            atomic->setGeometry( geometryI->second );            
            TextureI textureI = _textures.find( importData->lightmapId );
            if( textureI != _textures.end() ) 
            {
                atomic->setLightMap( textureI->second );
            }
            _atomics.insert( AtomicT( importData->id, atomic ) );
            iImport->release( importData );
        }
        break;
    case import::itClump:
        {
            import::ImportClump* importData = iImportStream->importClump();
            Clump* clump = new Clump( importData->name );
            FrameI frameI = _frames.find( importData->frameId );
            assert( frameI != _frames.end() );
            clump->setFrame( frameI->second );
            frameI->second->dirty();
            for( int i=0; i<importData->numAtomics; i++ )
            {
                AtomicI atomicI = _atomics.find( importData->atomics[i] );
                assert( atomicI != _atomics.end() );
                clump->add( atomicI->second );
            }
开发者ID:Jan123457,项目名称:d3basejumper,代码行数:67,代码来源:importasset.cpp

示例14: Geometry

void
Triangle_Processor::Process( Stack<AtomicRegion>&  Offspring)
  {
  TimesCalled ++;
  if (TimesCalled == 1)
    {
    TheRule->Apply(LocalIntegrand(),Geometry(),Integral(),AbsoluteError());
    Offspring.MakeEmpty();
    return;
    };
  if(TimesCalled == 2)
    {
    real NewVolume
          = Geometry().Volume()/2;
    Stack<Triangle> Parts;
    Vector<unsigned int> DiffOrder(Diffs.Size());
    const real difffac = real(1)/real(0.45);    
    const real difftreshold = 1e-3;

    TheRule->ComputeDiffs(LocalIntegrand(),Geometry(),Diffs); 

    // Sort the differences in descending order.
    for (unsigned int ik=0 ; ik<=2 ; ik++)  { DiffOrder[ik] = ik; }
    for (unsigned int i=0 ; i<=1 ; i++)  
      {
     for (unsigned int k=i+1 ; k<=2 ; k++)
         if (Diffs[DiffOrder[k]]>Diffs[DiffOrder[i]])
            {
            unsigned int h = DiffOrder[i];
            DiffOrder[i] = DiffOrder[k];
            DiffOrder[k] = h;
            }
      }

    if (Diffs[DiffOrder[0]] < difftreshold)
      {
      TheDivisor4->Apply(Geometry(),Parts,DiffOrder);
      NewVolume /=2;
      }
    else 
      {
      if (Diffs[DiffOrder[0]]>difffac*Diffs[DiffOrder[2]])
        {
        TheDivisor2->Apply (Geometry(),Parts,DiffOrder);
        }
      else 
        { 
        TheDivisor4->Apply(Geometry(),Parts,DiffOrder);
        NewVolume /=2;
        }	
      };

    unsigned int N = Parts.Size();
    for (unsigned int ii =0;ii<N;ii++)
      {
      Triangle* g = Parts.Pop();
      g->Volume(NewVolume);
      Processor<Triangle>* p = Descendant();
      Atomic<Triangle>* a = new Atomic<Triangle>(g,p);
      a->LocalIntegrand(&LocalIntegrand());
      Offspring.Push(a);
      };
    return;
    };
   Error(TimesCalled > 2,
     "Triangle_Processor : more than two calls of Process()");
   }
开发者ID:kwrobert,项目名称:ResearchCode,代码行数:67,代码来源:T2prc.cpp

示例15: ANKI_TEST

//==============================================================================
ANKI_TEST(Resource, AsyncLoader)
{
	HeapAllocator<U8> alloc(allocAligned, nullptr);

	// Simple create destroy
	{
		AsyncLoader a;
		a.init(alloc);
	}

	// Simple task that will finish
	{
		AsyncLoader a;
		a.init(alloc);
		Barrier barrier(2);

		a.submitNewTask<Task>(0.0, &barrier, nullptr);
		barrier.wait();
	}

	// Many tasks that will finish
	{
		AsyncLoader a;
		a.init(alloc);
		Barrier barrier(2);
		Atomic<U32> counter = {0};
		const U COUNT = 100;

		for(U i = 0; i < COUNT; i++)
		{
			Barrier* pbarrier = nullptr;

			if(i == COUNT - 1)
			{
				pbarrier = &barrier;
			}

			a.submitNewTask<Task>(0.01, pbarrier, &counter);
		}

		barrier.wait();

		ANKI_TEST_EXPECT_EQ(counter.load(), COUNT);
	}

	// Many tasks that will _not_ finish
	{
		AsyncLoader a;
		a.init(alloc);

		for(U i = 0; i < 100; i++)
		{
			a.submitNewTask<Task>(0.0, nullptr, nullptr);
		}
	}

	// Tasks that allocate
	{
		AsyncLoader a;
		a.init(alloc);
		Barrier barrier(2);

		for(U i = 0; i < 10; i++)
		{
			Barrier* pbarrier = nullptr;

			if(i == 9)
			{
				pbarrier = &barrier;
			}

			a.submitNewTask<MemTask>(alloc, pbarrier);
		}

		barrier.wait();
	}

	// Tasks that allocate and never finished
	{
		AsyncLoader a;
		a.init(alloc);

		for(U i = 0; i < 10; i++)
		{
			a.submitNewTask<MemTask>(alloc, nullptr);
		}
	}

	// Pause/resume
	{
		AsyncLoader a;
		a.init(alloc);
		Atomic<U32> counter(0);
		Barrier barrier(2);

		// Check if the pause will sync
		a.submitNewTask<Task>(0.5, nullptr, &counter, 0);
		HighRezTimer::sleep(0.25); // Wait for the thread to pick the task...
		a.pause(); /// ...and then sync
//.........这里部分代码省略.........
开发者ID:Al1a123,项目名称:anki-3d-engine,代码行数:101,代码来源:AsyncLoader.cpp


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