summaryrefslogtreecommitdiff
path: root/library/multithreading.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 16:47:21 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 16:47:21 +0200
commitca64896d49b70fc0ffec711a079167c972fe635e (patch)
tree0059c36336378c886b750860aa5343b847c3609a /library/multithreading.h
parent1.3 (diff)
downloadFreeFileSync-ca64896d49b70fc0ffec711a079167c972fe635e.tar.gz
FreeFileSync-ca64896d49b70fc0ffec711a079167c972fe635e.tar.bz2
FreeFileSync-ca64896d49b70fc0ffec711a079167c972fe635e.zip
1.4
Diffstat (limited to 'library/multithreading.h')
-rw-r--r--library/multithreading.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/library/multithreading.h b/library/multithreading.h
new file mode 100644
index 00000000..8466bb01
--- /dev/null
+++ b/library/multithreading.h
@@ -0,0 +1,64 @@
+#ifndef MULTITHREADING_H_INCLUDED
+#define MULTITHREADING_H_INCLUDED
+
+#include <wx/string.h>
+#include <wx/thread.h>
+
+//interface for status updates (can be implemented by UI or commandline)
+//overwrite virtual methods for respective functionality
+class StatusUpdater
+{
+public:
+ StatusUpdater() : abortionRequested(false) {}
+ virtual ~StatusUpdater() {}
+
+ //these four 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() {}
+
+ void requestAbortion() //opportunity to abort must be implemented in the three virtual status and error methods (for example in triggerUI_Refresh())
+ { //currently used by the UI status information screen, when button "Abort is pressed"
+ abortionRequested = true;
+ }
+ static const int continueNext = -1;
+ static const int retry = -2;
+
+protected:
+ bool abortionRequested;
+};
+
+
+const int uiUpdateInterval = 100; //perform ui updates not more often than necessary, 100 seems to be a good value with only a minimal performance loss
+
+class WorkerThread;
+
+
+//class handling execution of a method while updating the UI
+class UpdateWhileExecuting
+{
+ friend class WorkerThread;
+
+public:
+ UpdateWhileExecuting();
+ virtual ~UpdateWhileExecuting();
+
+ void waitUntilReady();
+ void execAndUpdate(StatusUpdater* statusUpdater);
+
+
+private:
+ //implement a longrunning method without dependencies (e.g. copy file function) returning "true" on success
+ virtual void longRunner() = 0;
+
+ WorkerThread* theWorkerThread;
+
+ wxMutex readyToReceiveResult;
+ wxCondition receivingResult;
+};
+
+#endif // MULTITHREADING_H_INCLUDED
bgstack15