/** Increments counter once for each iteration in the iteration space. */ void operator()( tbb::blocked_range<size_t>& range ) const { for( size_t i=range.begin(); i!=range.end(); ++i ) { bool transaction_attempted = false; { typename C::mutex_type::scoped_lock lock(counter.mutex); if( IsInsideTx() ) transaction_attempted = true; counter.value = counter.value+1; } if( transaction_attempted ) ++n_transactions_attempted; __TBB_Pause(i); } }
void operator()( int id ) const { bool last = false; // The first barrier. if ( --Counter1 == 0 ) last = true; while ( !last && !Flag1.load<tbb::acquire>() ) __TBB_Pause( 1 ); // Save a time stamp of the first barrier releasing. tick_count_array[id] = tbb::tick_count::now(); // The second barrier. if ( --Counter2 == 0 ) Flag2.store<tbb::release>(true); // The last thread should release threads from the first barrier after it reaches the second // barrier to avoid a deadlock. if ( last ) Flag1.store<tbb::release>(true); // After the last thread releases threads from the first barrier it waits for a signal from // the second barrier. while ( !Flag2.load<tbb::acquire>() ) __TBB_Pause( 1 ); if ( last ) // We suppose that the barrier time is a time interval between the moment when the last // thread reaches the first barrier and the moment when the same thread is released from // the second barrier. This time is not accurate time of two barriers but it is // guaranteed that it does not exceed it. barrier_time = (tbb::tick_count::now() - tick_count_array[id]).seconds() / 2; }
void market::process( job& j ) { generic_scheduler& s = static_cast<generic_scheduler&>(j); arena *a = NULL; __TBB_ASSERT( governor::is_set(&s), NULL ); #if !__TBB_SLEEP_PERMISSION while ( (a = arena_in_need(a)) ) a->process(s); #else//__TBB_SLEEP_PERMISSION enum { query_interval = 1000, first_interval = 1, pause_time = 100 // similar to PauseTime used for the stealing loop }; for(int i = first_interval; ; i--) { while ( (a = arena_in_need(a)) ) { a->process(s); i = first_interval; } if( i == 0 ) { #if __TBB_TASK_PRIORITY arena_list_type &al = my_priority_levels[my_global_top_priority].arenas; #else /* __TBB_TASK_PRIORITY */ arena_list_type &al = my_arenas; #endif /* __TBB_TASK_PRIORITY */ if( al.empty() ) // races if any are innocent TODO: replace by an RML query interface break; // no arenas left, perhaps going to shut down if( the_global_observer_list.ask_permission_to_leave() ) break; // go sleep __TBB_Yield(); i = query_interval; } else __TBB_Pause(pause_time); } #endif//__TBB_SLEEP_PERMISSION GATHER_STATISTIC( ++s.my_counters.market_roundtrips ); }