INTRODUCTION
Overview
Download and Install
Quick Start
Documentation
Publications

NONFRAMEWORK CODE
Driver Interfaces
Drivers
Libraries
Utilities

FRAMEWORK CODE
Interfaces
Components
Libraries
Utilities

Full Software Listings

DEVELOPER
Tutorials
Examples
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

jobqueue.h

00001 /*
00002  * Orca-Robotics Project: Components for robotics
00003  *               http://!orca-robotics.sf.net/
00004  * Copyright (c) 2004-2009 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 <gbxutilacfr/stoppable.h>
00019 #include <gbxsickacfr/gbxiceutilacfr/thread.h>
00020 #include <hydroutil/uncopyable.h>
00021 #include <gbxutilacfr/tracer.h>
00022 #include <vector>
00023 #include <list>
00024 
00025 namespace hydroiceutil {
00026 
00027 
00035 class Job : public gbxutilacfr::Stoppable, public IceUtil::Shared
00036 {
00037 public:
00038     Job();
00039     virtual ~Job() {}
00040 
00043     virtual void execute()=0;
00044 
00046     virtual std::string toString() const=0;
00047 
00051     virtual int expectedDuration() const { return -1; };
00052 
00056     void cancel();
00057 
00059     bool isCancelled();
00060 
00061     // from gbxutilacfr::Stoppable
00064     virtual bool isStopping() { return isCancelled(); };
00065 
00071     bool isTracable_;
00072 
00073 private:
00074 
00075     bool isCancelled_;
00076     IceUtil::Mutex isCancelledMutex_;
00077 
00078 };
00080 typedef IceUtil::Handle<Job> JobPtr;
00081 
00083 struct JobQueueStatus
00084 {
00086     int activeJobCount;
00088     int queuedJobCount;
00089 };
00090 
00102 class JobQueue :  public IceUtil::Shared,
00103                   public IceUtil::Monitor<IceUtil::Mutex>,
00104                   private hydroutil::Uncopyable
00105 {
00106 public:
00108     struct Config
00109     {
00110         Config() :
00111             threadPoolSize(1),
00112             queueSizeWarn(0),
00113             traceAddEvents(false),
00114             traceStartEvents(false),
00115             traceDoneEvents(false),
00116             traceStalledJobs(false) {};
00117 
00119         void validate( gbxutilacfr::Tracer& tracer );
00120 
00123         int threadPoolSize;
00127         int queueSizeWarn;
00130         bool traceAddEvents;
00133         bool traceStartEvents;
00136         bool traceDoneEvents;
00139         bool traceStalledJobs;
00140 //         bool cancelStalledJobs;
00141     };
00142 
00148     JobQueue( gbxutilacfr::Tracer& tracer, const Config& config=Config() );
00149 
00151     ~JobQueue();
00152 
00157     void stop();
00158 
00160     void add( const JobPtr& job );
00161 
00163     JobQueueStatus status();
00164 
00166     std::string toString();
00167 
00168     //
00169     // No doxy-tags because these are only used by workers.
00170     //
00171 
00172     // The worker asks for a job to work on.
00173     // Blocks until a job arrives
00174     JobPtr get( gbxiceutilacfr::Thread* thread );
00175 
00176 private:
00177     // incoming job requests
00178     std::list<JobPtr>               pendingJobs_;
00179 
00180     // worker pool
00181     std::vector<gbxiceutilacfr::ThreadPtr> workerPool_;
00182     int activeJobCount_;
00183 
00184     bool isQueueStopping_;
00185 
00186     gbxutilacfr::Tracer& tracer_;
00187     Config config_;
00188 };
00190 typedef IceUtil::Handle<JobQueue> JobQueuePtr;
00191 
00192 } // namespace
00193 
00194 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5