InputHandlerThreaded.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef CHANNELS_INPUTHANDLERTHREADED_C_DEFINED
00039 #define CHANNELS_INPUTHANDLERTHREADED_C_DEFINED
00040
00041 #include "Channels/InputHandlerThreaded.H"
00042
00043 #include "Channels/SingleChannel.H"
00044 #include "Util/JobServer.H"
00045 #include "Util/JobWithSemaphore.H"
00046 #include "Util/MainJobServer.H"
00047
00048 #include <unistd.h>
00049
00050
00051 struct InputHandlerThreaded::Job : public JobWithSemaphore
00052 {
00053 Job(SingleChannel& chan_,
00054 const Image<float>& bwimg_,
00055 const SimTime& t_,
00056 const Image<byte>& clipMask_,
00057 const rutz::shared_ptr<PyramidCache<float> >& cache_);
00058
00059 virtual ~Job();
00060
00061 virtual void run();
00062
00063 virtual const char* jobType() const;
00064
00065 SingleChannel* const chan;
00066 Image<float> const bwimg;
00067 SimTime const t;
00068 Image<byte> const clipMask;
00069 rutz::shared_ptr<PyramidCache<float> > const cache;
00070
00071 private:
00072 Job(const Job&);
00073 Job& operator=(const Job&);
00074 };
00075
00076
00077 InputHandlerThreaded::Job::Job(SingleChannel& chan_,
00078 const Image<float>& bwimg_,
00079 const SimTime& t_,
00080 const Image<byte>& clipMask_,
00081 const rutz::shared_ptr<PyramidCache<float> >& cache_)
00082 :
00083 chan(&chan_), bwimg(bwimg_), t(t_), clipMask(clipMask_), cache(cache_)
00084 {}
00085
00086
00087 InputHandlerThreaded::Job::~Job()
00088 {}
00089
00090
00091 void InputHandlerThreaded::Job::run()
00092 {
00093
00094 this->chan->setClipPyramid(this->clipMask);
00095 this->chan->storePyramid(this->chan->computePyramid(this->bwimg, this->cache),
00096 this->t);
00097
00098 this->chan->storeOutputCache(this->chan->combineSubMaps());
00099 this->markFinished();
00100 }
00101
00102
00103 const char* InputHandlerThreaded::Job::jobType() const
00104 {
00105 return "SingleChannelInputJob";
00106 }
00107
00108
00109 InputHandlerThreaded::
00110 InputHandlerThreaded()
00111 :
00112 itsJob()
00113 {}
00114
00115
00116 InputHandlerThreaded::~InputHandlerThreaded()
00117 {}
00118
00119
00120 void InputHandlerThreaded::handleInput(SingleChannel& chan,
00121 const Image<float>& bwimg,
00122 const SimTime& t,
00123 const Image<byte>& clipMask,
00124 const rutz::shared_ptr<PyramidCache<float> >& cache)
00125 {
00126 itsJob = rutz::make_shared(new Job(chan, bwimg, t, clipMask, cache));
00127 ASSERT(itsJob.is_valid());
00128 getMainJobServer().enqueueJob(itsJob);
00129 }
00130
00131
00132 void InputHandlerThreaded::waitForOutput(SingleChannel& chan)
00133 {
00134 if (!itsJob.is_valid())
00135 return;
00136
00137 LDEBUG("waiting for thread job to complete for channel %s",
00138 chan.descriptiveName().c_str());
00139
00140 itsJob->wait();
00141
00142 itsJob.reset(NULL);
00143 }
00144
00145
00146 rutz::shared_ptr<InputHandler> InputHandlerThreaded::makeClone() const
00147 {
00148 return rutz::make_shared(new InputHandlerThreaded);
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158 #endif // CHANNELS_INPUTHANDLERTHREADED_C_DEFINED