1%% options 2 3copyright owner = Dirk Krause 4copyright year = 2013-xxxx 5SPDX-License-Identifier: BSD-3-Clause 6 7%% header 8 9#include "dk3conf.h" 10#include <libdk3c/dk3types.h> 11#include <libdk3c/dk3const.h> 12 13#include <wx/wxprec.h> 14#ifdef __BORLANDC__ 15#pragma hdrstop 16#endif 17#ifndef WX_PRECOMP 18#include <wx/wx.h> 19#endif 20#include <wx/thread.h> 21 22 23 24/** Protect code from concurrent execution, mainly for timer handlers. 25 In contrast to a critical section which delays execution of 26 code to avoid concurrent access to data this class skips 27 the execution of concurrent code. 28*/ 29class DkWxProcessingController 30{ 31 protected: 32 33 /** Prevent concurrent access. 34 */ 35 wxMutex mxProtectProcessing; 36 37 /** Flag: Processing is running. 38 */ 39 bool bIsRunning; 40 41 public: 42 /** Default constructor. 43 */ 44 DkWxProcessingController(); 45 46 /** Begin processing if not already running. 47 If the function returns true you must invoke endProcessing() 48 when your processing is finished. 49 @return true to start processing, false if processing is running. 50 */ 51 bool canBeginProcessing(void); 52 53 /** End processing. Call this function after finishing the 54 critical code. 55 */ 56 void endProcessing(void); 57}; 58 59%% module 60 61#include "dk3conf.h" 62#include <libdk3wx/DkWxProcessingController.h> 63 64$!trace-include 65 66DkWxProcessingController::DkWxProcessingController() 67{ 68 bIsRunning = false; 69} 70 71 72 73bool 74DkWxProcessingController::canBeginProcessing(void) 75{ 76 bool back = false; 77 { 78 wxMutexLocker lock(mxProtectProcessing); 79 if(!(bIsRunning)) { 80 bIsRunning = true; 81 back = true; 82 } 83 } 84 return back; 85} 86 87 88 89void 90DkWxProcessingController::endProcessing(void) 91{ 92 wxMutexLocker lock(mxProtectProcessing); 93 bIsRunning = false; 94} 95 96 97 98