Changeset 3823 for trunk/yat/utility/Scheduler.h
- Timestamp:
- Jul 16, 2019, 4:11:48 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/0.16-stable (added) merged: 3795,3797-3799,3807-3808,3810,3817-3818,3820
- Property svn:mergeinfo changed
-
trunk/yat/utility/Scheduler.h
r3694 r3823 5 5 6 6 /* 7 Copyright (C) 2014, 2015, 2016, 2017 Peter Johansson7 Copyright (C) 2014, 2015, 2016, 2017, 2019 Peter Johansson 8 8 9 9 This file is part of the yat library, http://dev.thep.lu.se/yat … … 23 23 */ 24 24 25 #include "config_public.h"26 25 #include "PriorityQueue.h" 27 26 #include "Queue.h" … … 31 30 #include <boost/shared_ptr.hpp> 32 31 33 #ifdef YAT_HAVE_ATOMIC34 #include <atomic>35 #endif36 32 #include <set> 37 33 #include <deque> … … 87 83 class Scheduler 88 84 { 89 #ifdef YAT_HAVE_ATOMIC90 typedef std::atomic<int> running_jobs_type;91 #else92 typedef int running_jobs_type;93 #endif94 85 public: 95 86 /** … … 218 209 }; // end class Worker 219 210 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 220 261 // \internal Class that handles job 221 262 class JobHandler 222 263 { 223 264 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); 227 266 228 267 void operator()(void); … … 237 276 238 277 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_; 245 280 }; 246 281 … … 263 298 void throw_if_error(void) const; 264 299 265 JobQueue queue_; 266 Queue<JobPtr> jobs_; 267 running_jobs_type running_jobs_; 268 mutable Queue<boost::exception_ptr> error_; 300 JobHandlerData data_; 269 301 boost::thread job_handler_; 270 302 }; // end class Scheduler
Note: See TracChangeset
for help on using the changeset viewer.