orca-robotics INTRODUCTION Overview Download and Install Documentation REPOSITORY Interfaces Drivers Libraries Utilities Software Map DEVELOPER Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
jobqueue.h00001 /* 00002 * Orca-Robotics Project: Components for robotics 00003 * http://!orca-robotics.sf.net/ 00004 * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp 00005 * 00006 * This distribution is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 00011 #ifndef HYDROICEUTIL_JOB_QUEUE_H 00012 #define HYDROICEUTIL_JOB_QUEUE_H 00013 00014 #include <IceUtil/Handle.h> 00015 #include <IceUtil/Shared.h> 00016 #include <IceUtil/Monitor.h> 00017 #include <IceUtil/Mutex.h> 00018 #include <gbxsickacfr/gbxiceutilacfr/thread.h> 00019 #include <hydroutil/uncopyable.h> 00020 #include <gbxsickacfr/gbxutilacfr/tracer.h> 00021 #include <vector> 00022 #include <list> 00023 00024 namespace hydroiceutil { 00025 00026 00034 class Job : public IceUtil::Shared 00035 { 00036 public: 00037 Job(); 00038 virtual ~Job() {} 00039 00042 virtual void execute()=0; 00043 00045 virtual std::string toString() const=0; 00046 00050 void cancel(); 00051 00053 bool isCancelled(); 00054 00055 private: 00056 00057 bool isCancelled_; 00058 IceUtil::Mutex isCancelledMutex_; 00059 00060 }; 00062 typedef IceUtil::Handle<Job> JobPtr; 00063 00065 struct JobQueueStatus 00066 { 00068 int activeJobCount; 00070 int queuedJobCount; 00071 }; 00072 00084 class JobQueue : public IceUtil::Shared, 00085 public IceUtil::Monitor<IceUtil::Mutex>, 00086 private hydroutil::Uncopyable 00087 { 00088 public: 00090 struct Config 00091 { 00092 Config() : 00093 threadPoolSize(1), 00094 queueSizeWarn(0), 00095 traceAddEvents(false), 00096 traceDoneEvents(false) {}; 00097 00099 void validate( gbxsickacfr::gbxutilacfr::Tracer& tracer ); 00100 00103 int threadPoolSize; 00106 int queueSizeWarn; 00109 bool traceAddEvents; 00112 bool traceDoneEvents; 00113 }; 00114 00118 JobQueue( gbxsickacfr::gbxutilacfr::Tracer& tracer, const Config& config=Config() ); 00119 00121 ~JobQueue(); 00122 00126 void stop(); 00127 00129 void add( const JobPtr& job ); 00130 00132 JobQueueStatus status(); 00133 00134 // 00135 // No doxy-tags because these are only used by workers. 00136 // 00137 00138 // The worker asks for a job to work on. 00139 // Blocks until a job arrives 00140 JobPtr get( gbxsickacfr::gbxiceutilacfr::Thread* thread ); 00141 00142 private: 00143 // incoming job requests 00144 std::list<JobPtr> pendingJobs_; 00145 00146 // worker pool 00147 std::vector<gbxsickacfr::gbxiceutilacfr::ThreadPtr> workerPool_; 00148 int activeJobCount_; 00149 00150 bool isQueueStopping_; 00151 00152 gbxsickacfr::gbxutilacfr::Tracer& tracer_; 00153 Config config_; 00154 }; 00156 typedef IceUtil::Handle<JobQueue> JobQueuePtr; 00157 00158 } // namespace 00159 00160 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)