1 #ifndef theplu_yat_utility_scheduler 2 #define theplu_yat_utility_scheduler 26 #include "PriorityQueue.h" 29 #include <boost/exception_ptr.hpp> 30 #include <boost/thread.hpp> 31 #include <boost/shared_ptr.hpp> 33 #ifdef YAT_HAVE_ATOMIC 89 #ifdef YAT_HAVE_ATOMIC 90 typedef std::atomic<int> running_jobs_type;
92 typedef int running_jobs_type;
104 explicit Job(
unsigned int prio=0);
122 friend class JobHandler;
123 mutable boost::mutex mutex_;
124 void add_prerequisite(
const boost::shared_ptr<Job>&);
127 size_t remove_prerequisite(
const boost::shared_ptr<Job>&);
128 void add_observer(
const boost::shared_ptr<Job>&);
131 std::set<boost::shared_ptr<Job> > prerequisite_;
133 std::vector<boost::shared_ptr<Job> > observers_;
139 enum status { pristine, prepared, running, completed};
143 boost::exception_ptr error_;
163 boost::shared_ptr<Job> prerequisite);
175 size_t jobs(
void)
const;
186 void submit(
const boost::shared_ptr<Job>& job);
194 typedef boost::shared_ptr<Scheduler::Job> JobPtr;
198 bool operator()(
const JobPtr& lhs,
const JobPtr& rhs)
const;
224 JobHandler(
unsigned int threads, JobQueue& queue,
Queue<JobPtr>& jobs,
225 running_jobs_type& running_jobs,
230 void process(JobPtr& job);
234 void prepare(JobPtr job);
236 void post_process(JobPtr job);
238 void send2queue(JobPtr& job);
239 unsigned int threads_;
242 running_jobs_type& running_jobs_;
252 void post_process(boost::shared_ptr<Job> job);
257 void process(boost::shared_ptr<Job> job);
260 void queue(boost::shared_ptr<Job> job);
263 void throw_if_error(
void)
const;
267 running_jobs_type running_jobs_;
269 boost::thread job_handler_;
Handle a number of jobs and send them to threads.
Definition: Scheduler.h:87
void submit(const boost::shared_ptr< Job > &job)
submit a job to Scheduler
Job(unsigned int prio=0)
constructor
The Department of Theoretical Physics namespace as we define it.
virtual void operator()(void)=0
virtual ~Job(void)
destructor
Definition: Scheduler.h:98
void interrupt(void)
interrrupt all jobs
void add_dependency(boost::shared_ptr< Job > job, boost::shared_ptr< Job > prerequisite)
add a dependency rule
void wait(void)
wait for all jobs to finish
unsigned int priority(void) const