ML 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 iteratively, allowing breaks and resumption at any time,...
Base class for single and multithreaded processor.
virtual void handleErrorsInGUIThread()
Handles all errors that have been accumulated.
ProcessingTimeLine::TimeLine * getOverviewTimeLine()
Returns access to the overview timeline (only if timeline 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)
Enables/disables timeline 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)
Returns 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()
Terminates all requests.
int _guiThreadRecursionCounter
The recursion of the GUI thread (0 = outer entry).
void setupCurrentProcessingScope()
Helper.
void enterProcessingScope() override
Enters a recursive processing scope. This is always called from main thread!
ProcessingTimeLine & getProcessingTimeLine()
Returns access to the processing timeline.
int getProcessingScope() const
Returns the current processing scope.
void leaveProcessingScope() override
Leaves a recursive processing scope. This is always called from main thread!
bool isTimeLineProfilingEnabled() const
Returns whether timeline 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 whether the calculation was terminated.
UserThreadData * getUserThreadData(PageRequest *request, PerThreadStorage &perThreadStorage)
Returns or allocates the UserThreadData for the given request as part of the perThreadStorage.
void addNewCursor(PageRequestCursor *cursor)
Adds the new cursor.
int _producerCursorCounter
How many cursors the producer contains in all lists.
std::vector< ScopeStackEntry > _scopeStack
Stack of processing scopes.
virtual bool supportsMultiThreading()=0
Returns whether multithreading 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 timeline 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:490
Data that is available on a per-thread basis to cache items 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.