Changeset 3349


Ignore:
Timestamp:
Nov 13, 2014, 4:59:26 AM (9 years ago)
Author:
Peter
Message:

avoid having a std::set just to count number of jobs. refs #800

Location:
trunk/yat/utility
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/Scheduler.cc

    r3348 r3349  
    3131
    3232  Scheduler::Scheduler(unsigned int threads)
     33    : running_jobs_(0)
    3334  {
    3435    assert(threads);
     
    4041  void Scheduler::post_process(JobPtr job)
    4142  {
    42     running_jobs_.erase(job);
     43    --running_jobs_;
     44    assert(running_jobs_>=0);
    4345    job->status_ = Job::completed;
    4446    // check if there are jobs waiting for job
     
    9092  {
    9193    job->status_ = Job::running;
    92     running_jobs_.insert(job);
     94    ++running_jobs_;
     95    assert(running_jobs_>0);
    9396    queue_.push(job);
    9497  }
     
    97100  void Scheduler::submit(JobPtr job)
    98101  {
     102    // If any job has been completed since last submission,
     103    // post-process the completed job
     104    JobPtr completed_job;
     105    while (completed_.try_pop(completed_job))
     106      post_process(completed_job);
    99107    process(job);
    100108  }
     
    103111  void Scheduler::wait(void)
    104112  {
    105     while (running_jobs_.size() || completed_.size()) {
     113    while (running_jobs_ || completed_.size()) {
    106114      JobPtr job;
    107115      completed_.pop(job);
  • trunk/yat/utility/Scheduler.h

    r3348 r3349  
    108108    /**
    109109       \brief submit a \a job to Scheduler
     110
     111       If \a job depends on other jobs, they are also submitted to the
     112       Scheduler.
    110113     */
    111114    void submit(boost::shared_ptr<Job> job);
     
    149152
    150153    typedef boost::shared_ptr<Scheduler::Job> JobPtr;
    151     std::set<JobPtr> running_jobs_;
     154    int running_jobs_;
    152155
    153156    // value lists all jobs that depend on key, i.e., key has to
Note: See TracChangeset for help on using the changeset viewer.