예제 #1
0
		void SchedulesBasedService::setRealTimeSchedules(
			size_t rank,
			boost::posix_time::time_duration departureSchedule,
			boost::posix_time::time_duration arrivalSchedule
		){
			recursive_mutex::scoped_lock lock(_generatedSchedulesMutex);
			_initRTSchedulesFromPlanned();

			if(!departureSchedule.is_not_a_date_time())
			{
				_RTDepartureSchedules[rank] = departureSchedule;
			}
			if(!arrivalSchedule.is_not_a_date_time())
			{
				_RTArrivalSchedules[rank] = arrivalSchedule;
				if(rank + 1 == _RTArrivalSchedules.size())
				{
					_computeNextRTUpdate();
				}
			}
			_path->markScheduleIndexesUpdateNeeded(true);


			// Inter-SYNTHESE sync
			if(Factory<InterSYNTHESESyncTypeFactory>::size()) // Avoid in unit tests
			{
				RealTimePTDataInterSYNTHESE::Content content(*this);
				inter_synthese::InterSYNTHESEModule::Enqueue(
					content,
					boost::optional<db::DBTransaction&>()
				);
			}
		}
예제 #2
0
///////////////////////////////////////////////////////////////////////////////
/// @fn CBroker::Schedule
/// @description Given a scheduleable task that should be run in the
///   future. The task will be scheduled to run by the Broker after the timer
///   expires and during the module that owns the timer's phase. The attempt to
///	  schedule may be rejected if the Broker is stopping, indicated by the return
///	  value.
/// @param h The handle to the timer being set.
/// @param wait the amount of the time to wait. If this value is "not_a_date_time"
///     The wait is converted to positive infinity and the time will expire as
///     soon as it is not the module that owns the timer's phase.
/// @param x A schedulable, a functor, that expects a single
/// 	boost::system::error_code parameter and returns void, created via
///		boost::bind()
/// @pre The module is registered
/// @post If the Broker is not stopping, the function is scheduled to be called
/// 	in the future. If a next time function is scheduled, its timer will
///     expire as soon as its round ends. If the Broker is stopping the task
///		will not be scheduled.
/// @return 0 on success, -1 if rejected
///////////////////////////////////////////////////////////////////////////////
int CBroker::Schedule(CBroker::TimerHandle h,
                      boost::posix_time::time_duration wait, CBroker::Scheduleable x)
{
    Logger.Trace << __PRETTY_FUNCTION__ << std::endl;
    {
        boost::unique_lock<boost::mutex> lock(m_stoppingMutex);
        if (m_stopping)
        {
            return -1;
        }
    }

    boost::mutex::scoped_lock schlock(m_schmutex);
    CBroker::Scheduleable s;
    if(wait.is_not_a_date_time())
    {
        wait = boost::posix_time::time_duration(boost::posix_time::pos_infin);
        m_nexttime[h] = true;
    }
    else
    {
        m_nexttime[h] = false;
    }
    m_timers[h]->expires_from_now(wait);
    s = boost::bind(&CBroker::ScheduledTask,this,x,h,boost::asio::placeholders::error);
    Logger.Debug<<"Scheduled task for timer "<<h<<std::endl;
    m_timers[h]->async_wait(s);

    return 0;
}
예제 #3
0
		std::string SchedulesBasedService::EncodeSchedule( const boost::posix_time::time_duration& value )
		{
			if(value.is_not_a_date_time())
			{
				return string();
			}

			std::stringstream os;

			os << std::setw( 2 ) << std::setfill ( '0' )
				<< (value.hours() / 24) << ":"
				<< std::setw( 2 ) << std::setfill ( '0' )
				<< (value.hours() % 24) << ":"
				<< std::setw( 2 ) << std::setfill ( '0' )
				<< value.minutes()
				;

			return os.str ();
		}
예제 #4
0
파일: Process.cpp 프로젝트: rstudio/rstudio
bool ProcessSupervisor::wait(
      const boost::posix_time::time_duration& pollingInterval,
      const boost::posix_time::time_duration& maxWait)
{
   boost::posix_time::ptime timeoutTime(boost::posix_time::not_a_date_time);
   if (!maxWait.is_not_a_date_time())
      timeoutTime = boost::get_system_time() + maxWait;

   while (poll())
   {
      // wait the specified polling interval
      boost::this_thread::sleep(pollingInterval);

      // check for timeout if appropriate
      if (!timeoutTime.is_not_a_date_time())
      {
         if (boost::get_system_time() > timeoutTime)
            return false;
      }
   }

   return true;
}