// calculation thread function void CalcPage::DoCalculation(void) { int mod; INTERLOCKED_(mutex) { modified = false; } do { LOG(__FUNCTION__ << " Start calculation"); // gets the status bar StatusBar &sb = ((Lamell *)(GetMainWindow()))->GetStatusBar(); { // signals calculation in progress GuiLock __; sb.Set("Calcolo in corso"); } calcAborted = !Calculate(); { // signals end of calculation GuiLock __; if(calcAborted) sb.Set("Errore"); else sb.Set("Pronto"); } INTERLOCKED_(mutex) { mod = modified; } LOG(__FUNCTION__ << " End calculation, modified = " << mod); } while(mod); } // modify handler -- triggers page calculation // on keypress on every (editable) ctrl on page void CalcPage::ModifyCb(void) { LOG(__FUNCTION__ << " ModifyCb called"); if(!calcThread.IsOpen()) { calcThread.Run(THISBACK(DoCalculation)); return; } INTERLOCKED_(mutex) { modified = true; } }
// calculation thread function void CalcPage::DoCalculation(void) { bool mod; INTERLOCKED_(mutex) { inThread = true; } do { INTERLOCKED_(mutex) { modified = false; } // gets the status bar StatusBar &sb = ((Lamell *)(GetMainWindow()))->GetStatusBar(); { // signals calculation in progress GuiLock __; sb.Set("Calcolo in corso"); } calcAborted = !Calculate(); { // signals end of calculation GuiLock __; if(calcAborted) sb.Set("Errore"); else sb.Set("Pronto"); } INTERLOCKED_(mutex) { mod = modified; } } while(mod); INTERLOCKED_(mutex) { inThread = false; } } // modify handler -- triggers page calculation // on keypress on every (editable) ctrl on page void CalcPage::ModifyCb(void) { bool inTh; INTERLOCKED_(mutex) { inTh = inThread; } if(!inTh) { calcThread.Run(THISBACK(DoCalculation)); return; } INTERLOCKED_(mutex) { modified = true; } }
void ThreadCb(void) { INTERLOCKED_(mutex) { inThread = true; } << DO SOME TIME CONSUMING STUFFS> INTERLOCKED_(mutex) { inThread = false; } bool StartThread(void) { bool inTh; INTERLOCKED_(mutex) { inTh = inThread; } if(inTh) return false; myThread.Run(ThreadCb); return true; }
void ThreadCb(void) { << DO SOME TIME CONSUMING STUFFS> INTERLOCKED_(mutex) { inThread = false; } bool StartThread(void) { bool inTh; INTERLOCKED_(mutex) { inTh = inThread; } if(inTh) return false; inThread = true; myThread.Run(ThreadCb); return true; }