Ignore:
Timestamp:
Jul 16, 2019, 4:11:48 AM (4 years ago)
Author:
Peter
Message:

Merge release 0.16 into trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/yat/utility/Scheduler.h

    r3694 r3823  
    55
    66/*
    7   Copyright (C) 2014, 2015, 2016, 2017 Peter Johansson
     7  Copyright (C) 2014, 2015, 2016, 2017, 2019 Peter Johansson
    88
    99  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2323*/
    2424
    25 #include "config_public.h"
    2625#include "PriorityQueue.h"
    2726#include "Queue.h"
     
    3130#include <boost/shared_ptr.hpp>
    3231
    33 #ifdef YAT_HAVE_ATOMIC
    34 #include <atomic>
    35 #endif
    3632#include <set>
    3733#include <deque>
     
    8783  class Scheduler
    8884  {
    89 #ifdef YAT_HAVE_ATOMIC
    90     typedef std::atomic<int> running_jobs_type;
    91 #else
    92     typedef int running_jobs_type;
    93 #endif
    9485  public:
    9586    /**
     
    218209    }; // end class Worker
    219210
     211
     212    class JobHandlerData
     213    {
     214    public:
     215      /// thread-safe class around int
     216      class Count
     217      {
     218      public:
     219        /// Constructor
     220        explicit Count(int x=0);
     221        /// increase value with 1
     222        void decrement(void);
     223        /// return value
     224        int get(void) const;
     225        /// decrease value with 1
     226        void increment(void);
     227        /// modify value
     228        void set(int x);
     229      private:
     230        mutable boost::mutex mutex_;
     231        int x_;
     232      };
     233
     234      JobHandlerData(unsigned int threads);
     235      Queue<boost::exception_ptr>& error(void) const;
     236
     237      const Queue<JobPtr>& jobs(void) const;
     238      Queue<JobPtr>& jobs(void);
     239      const JobQueue& queue(void) const;
     240      JobQueue& queue(void);
     241
     242      const Count& job_count(void) const;
     243      Count& job_count(void);
     244
     245      const Count& running_jobs(void) const;
     246      Count& running_jobs(void);
     247
     248      const Count& threads(void) const;
     249      Count& threads(void);
     250    private:
     251      mutable Queue<boost::exception_ptr> error_;
     252      Queue<JobPtr> jobs_;
     253      JobQueue queue_;
     254
     255      Count job_count_;
     256      Count running_jobs_;
     257      Count threads_;
     258    };
     259
     260
    220261    // \internal Class that handles job
    221262    class JobHandler
    222263    {
    223264    public:
    224       JobHandler(unsigned int threads, JobQueue& queue, Queue<JobPtr>& jobs,
    225                  running_jobs_type& running_jobs,
    226                  Queue<boost::exception_ptr>& error);
     265      JobHandler(JobHandlerData& data);
    227266
    228267      void operator()(void);
     
    237276
    238277      void send2queue(JobPtr& job);
    239       unsigned int threads_;
    240       JobQueue& queue_;
    241       Queue<JobPtr>& jobs_;
    242       running_jobs_type& running_jobs_;
    243       Queue<boost::exception_ptr>& error_;
    244       int job_counter_;
     278
     279      JobHandlerData* data_;
    245280    };
    246281
     
    263298    void throw_if_error(void) const;
    264299
    265     JobQueue queue_;
    266     Queue<JobPtr> jobs_;
    267     running_jobs_type running_jobs_;
    268     mutable Queue<boost::exception_ptr> error_;
     300    JobHandlerData data_;
    269301    boost::thread job_handler_;
    270302  }; // end class Scheduler
Note: See TracChangeset for help on using the changeset viewer.