summaryrefslogtreecommitdiff
path: root/library/multithreading.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 16:53:07 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 16:53:07 +0200
commit583d6a1fd6701e3d42c87285265b0b4f7657ab7c (patch)
tree78461dd1a74685252eef77b8e7d3b622d1be67ea /library/multithreading.h
parent1.9 (diff)
downloadFreeFileSync-583d6a1fd6701e3d42c87285265b0b4f7657ab7c.tar.gz
FreeFileSync-583d6a1fd6701e3d42c87285265b0b4f7657ab7c.tar.bz2
FreeFileSync-583d6a1fd6701e3d42c87285265b0b4f7657ab7c.zip
1.10
Diffstat (limited to 'library/multithreading.h')
-rw-r--r--library/multithreading.h26
1 files changed, 20 insertions, 6 deletions
diff --git a/library/multithreading.h b/library/multithreading.h
index feecce5f..161fd687 100644
--- a/library/multithreading.h
+++ b/library/multithreading.h
@@ -4,6 +4,12 @@
#include <wx/string.h>
#include <wx/thread.h>
+const int UI_UPDATE_INTERVAL = 100; //perform ui updates not more often than necessary, 100 seems to be a good value with only a minimal performance loss
+
+bool updateUiIsAllowed(); //test if a specific amount of time is over
+void updateUiNow(); //do the updating
+
+
//interface for status updates (can be implemented by UI or commandline)
//overwrite virtual methods for respective functionality
class StatusUpdater
@@ -13,16 +19,24 @@ public:
abortionRequested(false) {}
virtual ~StatusUpdater() {}
- //these four methods have to be implemented in the derived classes to handle error and status information
+ //these methods have to be implemented in the derived classes to handle error and status information
virtual void updateStatusText(const wxString& text) = 0;
virtual void initNewProcess(int objectsTotal, double dataTotal, int processID) = 0; //informs about the total amount of data that will be processed from now on
virtual void updateProcessedData(int objectsProcessed, double dataProcessed) = 0; //called periodically after data was processed
virtual int reportError(const wxString& text) = 0;
- //this method is triggered repeatedly and can be used to refresh the ui by dispatching pending events
- virtual void triggerUI_Refresh(bool asyncProcessActive = false) = 0;
+ //this method is triggered repeatedly by requestUiRefresh() and can be used to refresh the ui by dispatching pending events
+ virtual void forceUiRefresh() = 0;
+ void requestUiRefresh(bool asyncProcessActive = false)
+ {
+ if (updateUiIsAllowed()) //test if specific time span between ui updates is over
+ forceUiRefresh();
- void requestAbortion() //opportunity to abort must be implemented in a frequently executed method like triggerUI_Refresh()
+ if (abortionRequested && !asyncProcessActive)
+ abortThisProcess(); //abort can be triggered by requestAbortion()
+ }
+
+ void requestAbortion() //opportunity to abort must be implemented in a frequently executed method like requestUiRefresh()
{ //currently used by the UI status information screen, when button "Abort is pressed"
abortionRequested = true;
}
@@ -31,12 +45,12 @@ public:
static const int retry = -2;
protected:
+ virtual void abortThisProcess() = 0;
+
bool abortionRequested;
};
-const int UI_UPDATE_INTERVAL = 100; //perform ui updates not more often than necessary, 100 seems to be a good value with only a minimal performance loss
-
class WorkerThread;
bgstack15