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


C++ tbb::atomic类代码示例

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


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

示例1: wait

	void wait(ogl_device& ogl)
	{	
		int delay = 0;
		if(!ogl.invoke([this]{return ready();}, high_priority))
		{
			while(!ogl.invoke([this]{return ready();}, normal_priority) && delay < 20)
			{
				delay += 2;
				Sleep(2);
			}
		}
		
		static tbb::atomic<size_t> count;
		static tbb::atomic<bool> warned;
		
		if(delay > 2 && ++count > 50)
		{
			if(!warned.fetch_and_store(true))
			{
				CASPAR_LOG(warning) << L"[fence] Performance warning. GPU was not ready during requested host read-back. Delayed by atleast: " << delay << L" ms. Further warnings are sent to trace log level."
									<< L" You can ignore this warning if you do not notice any problems with output video. This warning is caused by insufficent support or performance of your graphics card for OpenGL based memory transfers. "
									<< L" Please try to update your graphics drivers or update your graphics card, see recommendations on (www.casparcg.com)."
									<< L" Further help is available at (www.casparcg.com/forum).";
			}
			else
				CASPAR_LOG(trace) << L"[fence] Performance warning. GPU was not ready during requested host read-back. Delayed by atleast: " << delay << L" ms.";
		}
	}
开发者ID:Mistobaan,项目名称:CasparCG,代码行数:28,代码来源:fence.cpp

示例2: incLoopLog

/*
 * Use atomic compare-and-swap to update val to
 * val + inc (*in log-space*).  Update occurs in a loop in case other
 * threads update in the meantime.
 */
inline void incLoopLog(tbb::atomic<double>& val, double inc) {
	double oldMass = val.load();
	double returnedMass = oldMass;
	double newMass{salmon::math::LOG_0};
	do {
	  oldMass = returnedMass;
 	  newMass = salmon::math::logAdd(oldMass, inc);
	  returnedMass = val.compare_and_swap(newMass, oldMass);
	} while (returnedMass != oldMass);
}
开发者ID:xtmgah,项目名称:salmon,代码行数:15,代码来源:SalmonUtils.hpp

示例3: incLoop

/*
 * Use atomic compare-and-swap to update val to
 * val + inc.  Update occurs in a loop in case other
 * threads update in the meantime.
 */
inline void incLoop(tbb::atomic<double>& val, double inc) {
        double oldMass = val.load();
        double returnedMass = oldMass;
        double newMass{oldMass + inc};
        do {
            oldMass = returnedMass;
            newMass = oldMass + inc;
            returnedMass = val.compare_and_swap(newMass, oldMass);
        } while (returnedMass != oldMass);
}
开发者ID:xtmgah,项目名称:salmon,代码行数:15,代码来源:SalmonUtils.hpp

示例4: operator

    void operator () (const tbb::blocked_range<int> &range) const {
        int j;
        for(j=range.begin(); j<range.end(); j++) {
            //printf("Inner Loop Body (x,y)=(%d,%d) where y in [%d,%d)\n", i,j,range.begin(), range.end() );
	    int oldGatek;
            int freshNode,currentEdge;

            currentEdge = vertices[currentLevelSet[i]]+j;
            // let's handle one edge
#ifdef XBOFILE
            freshNode = edges[currentEdge][1]; // 0 RTM, value was prefetched
#else
            freshNode = edges[currentEdge];    // 0 RTM, value was prefetched
#endif
            oldGatek = -1;
            // test gatekeeper 
            oldGatek = gatekeeper[freshNode].fetch_and_increment();
	    if (oldGatek == 0) { // destination vertex unvisited!
                // increment newLevelIndex atomically
                int myIndex = newLevelIndex.fetch_and_increment();
	        // store fresh node in new level
	        newLevelSet[myIndex] = freshNode;

	        level[freshNode] = currentLevel + 1;
	    } // end if freshNode
        } // end for j
    }
开发者ID:atzannes,项目名称:TBBBenchmarks,代码行数:27,代码来源:bfs.cpp

示例5: logAddMass

inline void logAddMass(tbb::atomic<double>& bin,
                       double newMass) {
      double oldVal = bin;
      double retVal = oldVal;
      double newVal = 0.0;
      do {
          oldVal = retVal;
          newVal = salmon::math::logAdd(oldVal, newMass);
          retVal = bin.compare_and_swap(newVal, oldVal);
      } while (retVal != oldVal);
}
开发者ID:blahah,项目名称:salmon,代码行数:11,代码来源:FragmentStartPositionDistribution.cpp

示例6: do_schedule

    namespace Internal {
        
        static tbb::atomic< bool > s_have_pinning_observer;

		namespace {
			static pinning_observer * s_po = NULL;
			struct poi {
				~poi() { delete s_po; }
			};
			static poi s_poi;
		}

        //        template< typename Step >
        class simplest_scheduler::TaskWrapper : public tbb::task
        {
        public: 
            tbb::task * execute()
            {
                CNC_ASSERT( m_schedulable );
                m_schedulable->scheduler().do_execute( m_schedulable );
                return NULL;
            }

            TaskWrapper( schedulable * s ) : 
                m_schedulable( s )
            {}

        private:
            schedulable * m_schedulable;
        };

        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
        simplest_scheduler::simplest_scheduler( context_base &context, int numThreads, int htstride ) 
            : scheduler_i( context ),
              m_status(),
              m_rootTask(),
              m_initTBB( std::max( 2, numThreads + ( distributor::myPid() == 0 ? 0 : 1 ) ) ),
              m_taskGroupContext( tbb::task_group_context::isolated, tbb::task_group_context::default_traits | tbb::task_group_context::concurrent_wait )
        {
            //            {Speaker oss; oss << std::max( 2, numThreads + ( distributor::myPid() == 0 ? 0 : 1 ) );}
			if( htstride && s_have_pinning_observer.compare_and_swap( true, false ) == false ) {
				s_po = new pinning_observer( htstride );
			}
            m_status = COMPLETED;
            m_rootTask = new( tbb::task::allocate_root( m_taskGroupContext ) ) tbb::empty_task;
            m_rootTask->set_ref_count( 1 );
        }

        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        simplest_scheduler::~simplest_scheduler()
        {
            m_rootTask->decrement_ref_count();
            m_rootTask->destroy( *m_rootTask );
        }

        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        void simplest_scheduler::do_schedule( schedulable * stepInstance )
        { 
            m_status.compare_and_swap( RUNNING, COMPLETED );
            //            tbb_waiter * _waitTask = new( tbb::task::allocate_root() ) TaskWrapper( stepInstance );
            TaskWrapper * newTask = new( tbb::task::allocate_additional_child_of( *m_rootTask ) ) TaskWrapper( stepInstance );
            //tbb::task::enqueue( *newTask );
            tbb::task::spawn( *newTask );
        }

        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        void simplest_scheduler::wait( const inflight_counter_type & /*steps_in_flight*/ )
        {
            m_rootTask->wait_for_all();
            m_status = COMPLETED;
        }
    } // namespace Internal
开发者ID:baskarang,项目名称:icnc,代码行数:80,代码来源:simplest_scheduler.cpp

示例7: execute

    namespace Internal {

        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		
        static tbb::atomic< bool > s_have_pinning_observer;
		
		namespace {
			static pinning_observer * s_po = NULL;
			struct poi {
				~poi() { delete s_po; }
			};
			static poi s_poi;
		}

        template<typename Body>
        class simplest_prioritized_scheduler::TaskWrapper2 : public tbb::task
        {
            const Body& my_body;
            typename Body::argument_type my_value;
            TaskWrapper2< Body > * toBeReturned;

        public: 
            task* execute() {
                my_body(my_value); 
                return toBeReturned;
            };

            void setNext(TaskWrapper2<Body>* givenNext) { toBeReturned = givenNext; }

            TaskWrapper2( const typename Body::argument_type& value, const Body& body ) : 
                my_body(body), my_value(value), toBeReturned(NULL){}
        };

        class simplest_prioritized_scheduler::apply_step_instance
        {
        public:
            void operator()( schedulable * stepInstance ) const
            {
                CNC_ASSERT( stepInstance );
                stepInstance->scheduler().do_execute( stepInstance );
            }

            typedef schedulable * argument_type;
        };

        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        simplest_prioritized_scheduler::simplest_prioritized_scheduler( context_base &context, int numThreads, int htstride ) 
            : scheduler_i( context ),
              m_runQueue(),
              m_status(),
              m_allocated(),
              m_initTBB( numThreads  + ( distributor::myPid() == 0 ? 0 : 1 ) ),
              m_applyStepInstance( NULL )
        {
			if( htstride && s_have_pinning_observer.compare_and_swap( true, false ) == false ) {
				s_po = new pinning_observer( htstride );
			}
            m_status = COMPLETED;
            m_allocated = false;
            if( m_allocated.compare_and_swap( true, false ) == false ) {
                m_applyStepInstance = new apply_step_instance();
            }

        }

        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        simplest_prioritized_scheduler::~simplest_prioritized_scheduler()
        {
            if( m_allocated.compare_and_swap( false, true ) == true ) {
                delete m_applyStepInstance;
            }
        }

        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        // bool simplest_prioritized_scheduler::is_active()
        // {
        //     return m_status != COMPLETED;
        // }

        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        void simplest_prioritized_scheduler::do_schedule( schedulable * stepInstance )
        { 
            m_status.compare_and_swap(RUNNING, COMPLETED);
            m_runQueue.push(stepInstance); //, stepInstance->priority());
        }

        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        void simplest_prioritized_scheduler::wait( const inflight_counter_type & /*steps_in_flight*/ )
        {
//.........这里部分代码省略.........
开发者ID:baskarang,项目名称:icnc,代码行数:101,代码来源:simplest_prioritized_scheduler.cpp

示例8: GetThreadSpecific

 /*override*/ tbb::task* execute() {
     if( my_depth>0 ) {
         int child_count = my_child_count;
         scheduler* my_sched = GetThreadSpecific();
         tbb::task& c  = *new( tbb::task::allocate_continuation() ) tbb::empty_task;
         c.set_ref_count( child_count );
         recycle_as_child_of(c);
         --child_count;
         if( Producer==my_sched ) {
             // produce a task and put it into Exchanger
             tbb::task* t = new( c.allocate_child() ) tbb::empty_task;
             --child_count;
             t = Exchanger.fetch_and_store(t);
             if( t ) this->spawn(*t);
         } else {
             tbb::task* t = Exchanger.fetch_and_store(NULL);
             if( t ) this->spawn(*t);
         }
         while( child_count ) {
             c.spawn( *new( c.allocate_child() ) TaskGenerator(my_child_count, my_depth-1) );
             --child_count;
         }
         --my_depth;
         return this;
     } else {
         tbb::task* t = Exchanger.fetch_and_store(NULL);
         if( t ) this->spawn(*t);
         return NULL;
     }
 }
开发者ID:GDXN,项目名称:fitsliberator,代码行数:30,代码来源:test_task_leaks.cpp

示例9: new

 /*override*/ tbb::task* execute() {
     if( my_depth>0 ) {
         int child_count = my_child_count;
         scheduler* my_sched = internal::governor::local_scheduler();
         tbb::task& c  = *new( allocate_continuation() ) tbb::empty_task;
         c.set_ref_count( child_count );
         recycle_as_child_of(c);
         --child_count;
         if( Producer==my_sched ) {
             // produce a task and put it into Exchanger
             tbb::task* t = new( c.allocate_child() ) tbb::empty_task;
             --child_count;
             t = Exchanger.fetch_and_store(t);
             if( t ) spawn(*t);
         } else {
             tbb::task* t = Exchanger.fetch_and_store(NULL);
             if( t ) spawn(*t);
         }
         while( child_count ) {
             tbb::task* t = new( c.allocate_child() ) TaskGenerator(my_child_count, my_depth-1);
             if( my_depth >4 ) enqueue(*t);
             else              spawn(*t);
             --child_count;
         }
         --my_depth;
         return this;
     } else {
         tbb::task* t = Exchanger.fetch_and_store(NULL);
         if( t ) spawn(*t);
         return NULL;
     }
 }
开发者ID:Havoc,项目名称:mangos-boost,代码行数:32,代码来源:test_task_leaks.cpp

示例10: operator

 bool operator()( T &v ) {
    v = (T)my_count.fetch_and_increment();
    if ( (int)v < N )
       return true;
    else
       return false;
 } 
开发者ID:MarkusSR1984,项目名称:Malloctest,代码行数:7,代码来源:test_source_node.cpp

示例11:

	PathEntity(const PathEntity &entity)
	{
		id = entity.id;
		traversing.store(entity.traversing);
		pathNodes = entity.pathNodes;
		position = entity.position;
	}
开发者ID:beyzend,项目名称:wss,代码行数:7,代码来源:wssserver.cpp

示例12: wrap_as_future

	virtual boost::unique_future<bool> send(const safe_ptr<read_frame>& frame) override
	{
		bool pushed = frame_buffer_.try_push(frame);

		if (pushed && !first_frame_reported_)
		{
			first_frame_promise_.set_value();
			first_frame_reported_ = true;
		}

		return caspar::wrap_as_future(is_running_.load());
	}
开发者ID:ScarlettCode,项目名称:Server,代码行数:12,代码来源:channel_producer.cpp

示例13: new

        simplest_scheduler::simplest_scheduler( context_base &context, int numThreads, int htstride ) 
            : scheduler_i( context ),
              m_status(),
              m_rootTask(),
              m_initTBB( std::max( 2, numThreads + ( distributor::myPid() == 0 ? 0 : 1 ) ) ),
              m_taskGroupContext( tbb::task_group_context::isolated, tbb::task_group_context::default_traits | tbb::task_group_context::concurrent_wait )
        {
            //            {Speaker oss; oss << std::max( 2, numThreads + ( distributor::myPid() == 0 ? 0 : 1 ) );}
			if( htstride && s_have_pinning_observer.compare_and_swap( true, false ) == false ) {
				s_po = new pinning_observer( htstride );
			}
            m_status = COMPLETED;
            m_rootTask = new( tbb::task::allocate_root( m_taskGroupContext ) ) tbb::empty_task;
            m_rootTask->set_ref_count( 1 );
        }
开发者ID:baskarang,项目名称:icnc,代码行数:15,代码来源:simplest_scheduler.cpp

示例14: wrap_as_future

	virtual boost::unique_future<bool> send(const safe_ptr<core::read_frame>& frame) override
	{
		auto buffer = std::make_shared<audio_buffer_16>(
			core::audio_32_to_16(core::get_rearranged_and_mixed(frame->multichannel_view(), channel_layout_, channel_layout_.num_channels)));

		if (!input_.try_push(std::make_pair(frame, buffer)))
			graph_->set_tag("dropped-frame");

		if (Status() != Playing && !started_)
		{
			sf::SoundStream::Initialize(2, format_desc_.audio_sample_rate);
			Play();
			started_ = true;
		}

		return wrap_as_future(is_running_.load());
	}
开发者ID:AurelienRevault,项目名称:Caspar-Server,代码行数:17,代码来源:oal_consumer.cpp

示例15:

        simplest_prioritized_scheduler::simplest_prioritized_scheduler( context_base &context, int numThreads, int htstride ) 
            : scheduler_i( context ),
              m_runQueue(),
              m_status(),
              m_allocated(),
              m_initTBB( numThreads  + ( distributor::myPid() == 0 ? 0 : 1 ) ),
              m_applyStepInstance( NULL )
        {
			if( htstride && s_have_pinning_observer.compare_and_swap( true, false ) == false ) {
				s_po = new pinning_observer( htstride );
			}
            m_status = COMPLETED;
            m_allocated = false;
            if( m_allocated.compare_and_swap( true, false ) == false ) {
                m_applyStepInstance = new apply_step_instance();
            }

        }
开发者ID:baskarang,项目名称:icnc,代码行数:18,代码来源:simplest_prioritized_scheduler.cpp


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