MeVisLab Toolbox Reference
mlPageRequestProcessorBase.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2009, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_PAGE_REQUEST_PROCESSOR_BASE_H
14 #define ML_PAGE_REQUEST_PROCESSOR_BASE_H
15 
16 #include "mlInitSystemML.h"
17 
18 #include "mlPageRequestProcessor.h"
19 #include "mlProcessingTimeLine.h"
20 
21 #include <deque>
22 #include <map>
23 #include <vector>
24 
25 
26 ML_START_NAMESPACE
27 
28 class Host;
29 class PagedImage;
30 class UserThreadData;
31 
32 //-------------------------------------------------------------------------------------------
34 //-------------------------------------------------------------------------------------------
36 {
37 public:
40 
42  virtual bool supportsMultiThreading() = 0;
43 
47  void removeCancelledRequests() override;
48 
50  ProcessingTimeLine& getProcessingTimeLine() { return _profile; }
51 
53  ProcessingTimeLine::TimeLine* getOverviewTimeLine() { return _useTimeLineProfiling?_overviewTimeLine:nullptr; }
54 
56  void enableTimeLineProfiling(bool flag);
57 
59  bool isTimeLineProfilingEnabled() const { return _useTimeLineProfiling; }
60 
62  int getProcessingScope() const { return _processingScope; }
63 
65  void enterProcessingScope() override;
66 
68  void leaveProcessingScope() override;
69 
70 protected:
72  bool createMoreWork(bool sleepWhenBlocked, bool* allBlocked = nullptr, MLint pageRequestLimit = 100000, MLint* resultPageRequestCount = nullptr);
73 
76 
78  virtual void handleErrorsInGUIThread();
79 
82 
85 
87  virtual void getAllPageRequestQueues(std::vector< std::deque<PageRequest*>* >& queues);
88 
91 
94 
97 
100  std::vector< std::vector<PageRequestCursor*> > _cursors;
101 
109 
118 
122  {
124  rootTilesToWaitFor = 0;
125  errorOccurred = false;
126  }
127 
129  std::deque<PageRequest*> guiQueue;
132 
135 
137  std::vector<PageRequest*> pageRequestsWithErrors;
138  };
139 
142 
145  std::vector<ScopeStackEntry> _scopeStack;
146 
149 
154  ~PerThreadStorage() { clear(); }
155 
157  void clear();
158 
161  std::map<PagedImage*, UserThreadData*> userThreadDataMap;
162  };
163 
166 
169 
170 };
171 
172 ML_END_NAMESPACE
173 
174 #endif
175 
The Host is the central image processing class in the ML.
Definition: mlHost.h:115
A cursor to create page and tile requests in an iterative manner, to allow breaking/resuming at any t...
Base class for single and multi-threaded processor.
virtual void handleErrorsInGUIThread()
handle all errors that have been accumulated
ProcessingTimeLine::TimeLine * getOverviewTimeLine()
Get access to the overview time line (only if time line profiling is on)
int _processingScope
the current processing scope (0 = BG tasks, 1 = normal get tile, >1 = recursive get tile
ProcessingTimeLine::TimeLine * _overviewTimeLine
void removeCancelledRequests() override
Removes all requests that are canceled and no longer needed.
TimeCounter _progressUpdateTimer
Timer used for progress update from GUI thread.
void enableTimeLineProfiling(bool flag)
Enable/disable time line profiling.
bool createMoreWork(bool sleepWhenBlocked, bool *allBlocked=nullptr, MLint pageRequestLimit=100000, MLint *resultPageRequestCount=nullptr)
Creates more work items, returns true if new work was created.
ProcessingTimeLine::TimeLine * _guiThreadTimeLine
virtual void getAllPageRequestQueues(std::vector< std::deque< PageRequest * > * > &queues)
get all page request queues (to be derived when there are more than the GUI queues)
int _producerProcessingScope
the current cursor scope of the producer
PageRequestProcessorBase(Host *host)
void terminateAllRequestsInGUIThread()
terminate all requests
int _guiThreadRecursionCounter
the recursion of the GUI thread (0 = outer entry)
void setupCurrentProcessingScope()
helper
void enterProcessingScope() override
Enters a recursive processing scope (always called from main thread!)
ProcessingTimeLine & getProcessingTimeLine()
Get access to the processing time line.
int getProcessingScope() const
Return the current processing scope.
void leaveProcessingScope() override
Leaves a recursive processing scope (always called from main thread!)
bool isTimeLineProfilingEnabled() const
Returns if time line profiling is enabled.
int _rootTileRequests
the number of root tile requests, if this gets down to 0, we are done
Host * _host
optional pointer to the host
std::vector< std::vector< PageRequestCursor * > > _cursors
The cursors that are handled by the producer thread, one list for each processing scope.
PerThreadStorage _guiPerThreadStorage
The per thread storage for the GUI thread.
bool _terminated
flag if the calculation was terminated
UserThreadData * getUserThreadData(PageRequest *request, PerThreadStorage &perThreadStorage)
Gets or allocates the UserThreadData for the given request as part of the perThreadStorage.
void addNewCursor(PageRequestCursor *cursor)
add the new cursor
int _producerCursorCounter
how many cursors the producer contains in all lists
std::vector< ScopeStackEntry > _scopeStack
Stack of processing scopes for performance reasons, we only grow this stack, we never shrink it.
virtual bool supportsMultiThreading()=0
Returns if multi-threading is supported.
ScopeStackEntry * _currentScope
the current scope pointer
Abstract base class for page request processors.
A PageRequest represents the request for the calculation of a single page of a PagedImage.
Definition: mlPageRequest.h:32
Timeline for a single thread.
Stores a processing time line for multiple threads.
Class to measure precise time intervals.
Definition: mlTimeCounter.h:26
Base class for thread local data that is passed to CalculateOutputImageHandler::calculateOutputSubIma...
#define MLEXPORT
To export symbols from a dll/shared object, we need to mark them with the MLEXPORT symbol.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
Data this is available on a per-thread basis to cache things that are reused across PageRequest calls...
std::map< PagedImage *, UserThreadData * > userThreadDataMap
A map of UserThreadData for each PagedImage, UserThreadData objects are owned by the map.
void clear()
clears (and deletes) the cached data
Each processing scope has its own GUI work queue and flags/counters for errors and tiles to wait for.
bool errorOccurred
flag that indicates that an error occurred and that it needs to be handled in the GUI thread
std::deque< PageRequest * > guiQueue
the GUI work queue
int rootTilesToWaitFor
how many pending root tiles on this scope?
std::vector< PageRequest * > pageRequestsWithErrors
the list of page requests that have an error and need to be handled