%% options copyright owner = Dirk Krause copyright year = 2013-xxxx license = bsd %% header #include #include #include #include #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP #include #endif #include /** Protect code from concurrent execution, mainly for timer handlers. In contrast to a critical section which delays execution of code to avoid concurrent access to data this class skips the execution of concurrent code. */ class DkWxProcessingController { protected: /** Prevent concurrent access. */ wxMutex mxProtectProcessing; /** Flag: Processing is running. */ bool bIsRunning; public: /** Default constructor. */ DkWxProcessingController(); /** Begin processing if not already running. If the function returns true you must invoke endProcessing() when your processing is finished. @return true to start processing, false if processing is running. */ bool canBeginProcessing(void); /** End processing. Call this function after finishing the critical code. */ void endProcessing(void); }; %% module #include "DkWxProcessingController.h" $!trace-include DkWxProcessingController::DkWxProcessingController() { bIsRunning = false; } bool DkWxProcessingController::canBeginProcessing(void) { bool back = false; { wxMutexLocker lock(mxProtectProcessing); if(!(bIsRunning)) { bIsRunning = true; back = true; } } return back; } void DkWxProcessingController::endProcessing(void) { wxMutexLocker lock(mxProtectProcessing); bIsRunning = false; }