ML Reference
MeVis/Foundation/Sources/ML/include/host/mlClassicHost.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //-------------------------------------------------------------------------
00011 //-------------------------------------------------------------------------
00012 #ifndef __mlClassicHost_H
00013 #define __mlClassicHost_H
00014 
00015 //ML-includes
00016 #ifndef __mlInitSystemML_H
00017 #include "mlInitSystemML.h"
00018 #endif
00019 #ifndef __mlBasics_H
00020 #include "mlBasics.h"
00021 #endif
00022 #ifndef __mlPagedImage_H
00023 #include "mlPagedImage.h"
00024 #endif
00025 #ifndef __mlSubImage_H
00026 #include "mlSubImage.h"
00027 #endif
00028 #ifndef __mlWaitCondition_H
00029 #include "mlWaitCondition.h"
00030 #endif
00031 #ifndef __mlThread_H
00032 #include "mlThread.h"
00033 #endif
00034 
00035 #include <host/mlProcessingTimeLine.h>
00036 
00037 ML_START_NAMESPACE
00038 
00040 class Module;
00041 class ThreadDataClass;
00042 class ProcessAllPagesHandler;
00043 class Host;
00045 
00047 class MLEXPORT ClassicHost 
00048 {
00049 
00050 public:
00051   ClassicHost(Host* host);
00052   ~ClassicHost();
00053 
00054   //------------------------------------------------------
00056 
00057   //------------------------------------------------------
00058 
00071   MLErrorCode getTile(PagedImage&             outputImage,
00072                       SubImageBox             location,
00073                       MLDataType            dataType,
00074                       void**                data,
00075                       const ScaleShiftData& scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED;
00076 
00078 
00079   // ------------------------------------------------------------------------------
00081   // ------------------------------------------------------------------------------
00082   MLErrorCode processAllPages(Module&  module,
00083                                MLint      outputIndex,
00084                                SubImageBox  region,
00085                                ProcessAllPagesHandler* handler
00086                                ) ML_RETURN_VALUE_SHOULD_BE_USED;
00087 
00088   //----------------------------------------------------------------------------------------
00090   //----------------------------------------------------------------------------------------
00091   void shutdownWorkerThreads();
00092 
00094   void enableTimeLineProfiling(bool flag) { _useTimeLineProfiling = flag; }
00095 
00097   ProcessingTimeLine& getProcessingTimeLine() { return _profile; }
00098 
00099 protected:
00100 
00101   // ------------------------------------------------------------------------------
00116   // ------------------------------------------------------------------------------
00117   MLErrorCode _processPagesHelper(PagedImage             &outputImage,
00118                                   const SubImageBox      &location,
00119                                   MLDataType            dataType,
00120                                   void                 *data,
00121                                   const ScaleShiftData &scaleShiftData,
00122                                   bool                  calledByProcessAllPages) ML_RETURN_VALUE_SHOULD_BE_USED;
00123 
00124   ML_DISALLOW_COPY_AND_ASSIGN(ClassicHost)
00125 
00126   
00127 
00128 
00129   MLErrorCode _getTileCore(PagedImage             &outputImage,
00130                            SubImageBox             location,
00131                            MLDataType            dataType,
00132                            void                 *data,
00133                            const ScaleShiftData &scaleShiftData) ML_RETURN_VALUE_SHOULD_BE_USED;
00134 
00135   //------------------------------------------------------
00137 
00138   //------------------------------------------------------
00139 
00142 
00161   void _calcPages(PagedImage                 &outputImage,
00162                   const std::vector <MLint> pageIDs,
00163                   MLMemoryBlockHandle*      memoryBlockHandles);
00165 
00166   //----------------------------------------------------------------------------------------
00171   //----------------------------------------------------------------------------------------
00172   void _initializePageData(ThreadDataClass &tData, bool permitInCaching);
00173 
00174   //----------------------------------------------------------------------------------------
00178   //----------------------------------------------------------------------------------------
00179   static void _calcPagesMT(ThreadDataClass** threadDataContainers, ProcessingTimeLine::TimeLine* timeLine);
00180 
00182   friend struct CalcPagesWorkerThreadFunction;
00183 
00184   //----------------------------------------------------------------------------------------
00186   //----------------------------------------------------------------------------------------
00187   ThreadDataClass** _getWorkForWorkerThread(size_t workIndex);
00188 
00189   //----------------------------------------------------------------------------------------
00191   //----------------------------------------------------------------------------------------
00192   void _increaseErrorCounter();
00193 
00194   //------------------------------------------------------
00196 
00197   //------------------------------------------------------
00198 
00200   WaitCondition      _workAvailable;
00201 
00203   WaitCondition      _workDone;
00204 
00206   Mutex              _workAvailableMutex;
00207 
00209   std::vector<Thread*> _workerThreads;
00210 
00212   std::vector<ThreadDataClass**> _workerThreadClassData;
00213 
00215   bool               _shutdownWorkerThreadsFlag;
00216 
00219   Mutex              _countSyncMutex;
00220 
00222   MLint32            _errorCounter;
00223 
00225   MLint32            _numFinishedThreads;
00226 
00228   MLint32            _numLaunchedThreads;
00229 
00231   size_t             _maxNumPagesToCalculateInSingleWorkerThread;
00232 
00234   Host*              _host;
00235 
00236   ProcessingTimeLine _profile;
00237   ProcessingTimeLine::TimeLine* _guiTimeLine;
00238 
00239   std::vector<ProcessingTimeLine::TimeLine*> _workerThreadTimeLines;
00240   bool _useTimeLineProfiling;
00241 
00243 
00244 };
00245 
00246 ML_END_NAMESPACE
00247 
00248 #endif
00249 
00250 
00251