ML Reference
|
00001 // **InsertLicense** code 00002 //------------------------------------------------------------------------- 00017 //------------------------------------------------------------------------- 00018 #ifndef __mlHost_H 00019 #define __mlHost_H 00020 00021 //ML-includes 00022 #ifndef __mlInitSystemML_H 00023 #include "mlInitSystemML.h" 00024 #endif 00025 #ifndef __mlBasics_H 00026 #include "mlBasics.h" 00027 #endif 00028 #ifndef __mlPagedImage_H 00029 #include "mlPagedImage.h" 00030 #endif 00031 #ifndef __mlSubImage_H 00032 #include "mlSubImage.h" 00033 #endif 00034 #ifndef __mlFields_H 00035 #include "mlFields.h" 00036 #endif 00037 #ifndef __mlWaitCondition_H 00038 #include "mlWaitCondition.h" 00039 #endif 00040 #ifndef __mlBarrier_H 00041 #include "mlBarrier.h" 00042 #endif 00043 #ifndef __mlThread_H 00044 #include "mlThread.h" 00045 #endif 00046 00047 ML_START_NAMESPACE 00048 00050 class Module; 00051 class ThreadDataClass; 00052 class ProcessAllPagesHandler; 00054 00055 //------------------------------------------------------------------------- 00126 //------------------------------------------------------------------------- 00127 class MLEXPORT Host 00128 { 00129 00130 public: 00131 00132 friend class PageRequestProcessor; 00133 00134 //------------------------------------------------------ 00136 00137 //------------------------------------------------------ 00140 static void registerWithMemoryManager(); 00141 00145 Host(); 00146 00148 virtual ~Host(); 00150 00151 //--- Progress Callback 00153 void setProgressCB(void *userData, MLHostProgressCB *callback); 00154 00156 MLHostProgressCB *getProgressCB() const; 00157 00159 void *getProgressCBUserData() const; 00160 00167 void updateProgress(const char* info1, const char* info2); 00168 00169 //--- Break check callback 00171 void setBreakCheckCB(void *userData, MLHostBreakCheckCB *callback); 00172 00174 MLHostBreakCheckCB *getBreakCheckCB() const; 00175 00177 void *getBreakCheckCBUserData() const; 00178 00179 00182 bool shouldTerminate() const; 00183 00188 Field *getPressedNotifyField(); 00189 00191 static Host &getDefaultHost(); 00192 00194 static void destroyDefaultHost(); 00195 00199 static MLErrorCode pushDefaultHost(); 00200 00207 static MLErrorCode popDefaultHost(); 00208 00211 void setMaxNumThreads(MLint32 numThreads); 00212 00215 MLint32 getMaxNumThreads() const; 00216 00218 MLuint32 isProcessingActive() const; 00219 00220 00221 protected: 00224 void _setProcessingActive(); 00225 00229 void _unsetProcessingActive(); 00230 00231 public: 00232 //------------------------------------------------------ 00234 00235 //------------------------------------------------------ 00236 00249 MLErrorCode getTile(PagedImage& outputImage, 00250 SubImageBox location, 00251 MLDataType dataType, 00252 void** data, 00253 const ScaleShiftData& scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00254 00255 00272 MLErrorCode getTile(PagedImage& outputImage, 00273 SubImage& subImage, 00274 const ScaleShiftData& scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00275 00279 void freeTile(void* data); 00281 00282 //--------------------------------------------------------------------------- 00284 00285 //--------------------------------------------------------------------------- 00314 //--------------------------------------------------------------------------- 00315 MLErrorCode processAllPages(Module& module, 00316 MLint outputIndex, 00317 SubImageBox region=SubImageBox()) ML_RETURN_VALUE_SHOULD_BE_USED; 00318 00319 //------------------------------------------------------------------------------ 00322 //------------------------------------------------------------------------------ 00323 MLErrorCode processAllPages(Module& module, 00324 ProcessAllPagesHandler& handler, 00325 SubImageBox region=SubImageBox()) ML_RETURN_VALUE_SHOULD_BE_USED; 00326 00328 00329 //------------------------------------------------------ 00331 00332 //------------------------------------------------------ 00333 00342 MLErrorCode updateImageProperties(Module &module, MLint outputIndex) ML_RETURN_VALUE_SHOULD_BE_USED; 00343 00350 MLErrorCode updateImageProperties(PagedImage& outputImage) ML_RETURN_VALUE_SHOULD_BE_USED; 00352 00354 static inline unsigned int getMemoryManagerId() { return _memoryManagerId; } 00355 00358 static SubImageBox calculateInputSubImageBoxDebug(Module& module, int inIndex, const SubImageBox& outputSubImageBox, int outputIndex); 00359 00360 #ifdef ML_DEPRECATED 00361 00363 00364 00365 public: 00366 00369 ML_DEPRECATED MLErrorCode getTile(Module &op, 00370 MLint outIndex, 00371 SubImageBox loc, 00372 MLDataType dataType, 00373 void **data, 00374 const ScaleShiftData &scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00377 ML_DEPRECATED MLErrorCode getTile(Module &op, 00378 MLint outIndex, 00379 SubImage &subImg, 00380 const ScaleShiftData &scaleShiftData=ScaleShiftData()) ML_RETURN_VALUE_SHOULD_BE_USED; 00383 inline ML_DEPRECATED MLErrorCode updateImageProps(Module &op, MLint outIndex) ML_RETURN_VALUE_SHOULD_BE_USED { return updateImageProperties(op, outIndex); } 00384 00387 inline static ML_DEPRECATED SubImageBox calcInSubImageBoxDebug(Module& module, 00388 int inIndex, 00389 const SubImageBox& outSubImgBox, 00390 int outIndex) 00391 { 00392 return calculateInputSubImageBoxDebug(module, inIndex, outSubImgBox, outIndex); 00393 } 00394 00395 #endif // ML_DEPRECATED 00396 00397 00398 private: 00399 00400 // ------------------------------------------------------------------------------ 00402 // ------------------------------------------------------------------------------ 00403 MLErrorCode _processAllPages(Module& module, 00404 MLint outputIndex, 00405 SubImageBox region, 00406 ProcessAllPagesHandler* handler 00407 ) ML_RETURN_VALUE_SHOULD_BE_USED; 00408 00409 // ------------------------------------------------------------------------------ 00424 // ------------------------------------------------------------------------------ 00425 MLErrorCode _processPagesHelper(PagedImage &outputImage, 00426 const SubImageBox &location, 00427 MLDataType dataType, 00428 void *data, 00429 const ScaleShiftData &scaleShiftData, 00430 bool calledByProcessAllPages) ML_RETURN_VALUE_SHOULD_BE_USED; 00431 00433 Host(const Host &); 00434 00437 Host& operator=(const Host &); 00438 00442 MLErrorCode _requiredTypesRegisteredAndSupported(PagedImage* outputImage); 00443 00447 MLErrorCode _getTileCore(PagedImage &outputImage, 00448 SubImageBox location, 00449 MLDataType dataType, 00450 void *data, 00451 const ScaleShiftData &scaleShiftData) ML_RETURN_VALUE_SHOULD_BE_USED; 00452 00456 MLErrorCode _updateImageProperties(PagedImage* outputImage) ML_RETURN_VALUE_SHOULD_BE_USED; 00457 00458 00459 //------------------------------------------------------ 00461 00462 //------------------------------------------------------ 00463 00466 00485 void _calcPages(PagedImage &outputImage, 00486 const std::vector <MLint> pageIDs, 00487 MLMemoryBlockHandle* memoryBlockHandles); 00489 00490 //---------------------------------------------------------------------------------------- 00495 //---------------------------------------------------------------------------------------- 00496 void _initializePageData(ThreadDataClass &tData, bool permitInCaching); 00497 00498 //---------------------------------------------------------------------------------------- 00502 //---------------------------------------------------------------------------------------- 00503 static void _calcPagesMT(ThreadDataClass** threadDataContainers); 00504 00506 friend struct CalcPagesWorkerThreadFunction; 00507 00508 //---------------------------------------------------------------------------------------- 00510 //---------------------------------------------------------------------------------------- 00511 ThreadDataClass** _getWorkForWorkerThread(size_t workIndex); 00512 00513 //---------------------------------------------------------------------------------------- 00515 //---------------------------------------------------------------------------------------- 00516 void _shutdownWorkerThreads(); 00517 00518 //---------------------------------------------------------------------------------------- 00520 //---------------------------------------------------------------------------------------- 00521 void _increaseErrorCounter(); 00522 00523 //------------------------------------------------------ 00525 00526 //------------------------------------------------------ 00528 void* _userData; 00529 00531 MLHostProgressCB* _progressCB; 00532 00534 void* _breakCheckUserData; 00535 00537 MLHostBreakCheckCB* _breakCheckCB; 00538 00540 MLint32 _maxNumThreads; 00541 00543 MLuint32 _isProcessingActive; 00544 00546 WaitCondition _workAvailable; 00547 00549 WaitCondition _workDone; 00550 00552 Mutex _workAvailableMutex; 00553 00555 std::vector<Thread*> _workerThreads; 00556 00558 std::vector<ThreadDataClass**> _workerThreadClassData; 00559 00561 bool _shutdownWorkerThreadsFlag; 00562 00565 Mutex _countSyncMutex; 00566 00568 MLint32 _errorCounter; 00569 00571 MLint32 _numFinishedThreads; 00572 00574 MLint32 _numLaunchedThreads; 00575 00577 size_t _maxNumPagesToCalculateInSingleWorkerThread; 00578 00581 static unsigned int _memoryManagerId; 00583 00584 }; //End of class Host 00585 00586 ML_END_NAMESPACE 00587 00588 //----------------------------------------------------------------------------------- 00589 // Stream output for std::ostream 00590 //----------------------------------------------------------------------------------- 00591 namespace std { 00592 00594 MLEXPORT ostream& operator<<(ostream& s, const ML_NAMESPACE::Host &host); 00595 00596 } 00597 00598 #endif //of __mlHost_H 00599 00600 00601