X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fbackgroundsupr.cpp;fp=src%2Fbackgroundsupr.cpp;h=9eb806fda46d69f13f538ad5159222cdfed51f68;hp=129b38fa642482f11ed518daf37e06ef45f7caf2;hb=cd93aebb4dec4e0ae88d53f131c2320ae92d0cab;hpb=e98a8a9d72a7b919debbbc9d1b0f237fe71c0fb3 diff --git a/src/backgroundsupr.cpp b/src/backgroundsupr.cpp index 129b38f..9eb806f 100644 --- a/src/backgroundsupr.cpp +++ b/src/backgroundsupr.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2001 Kevin Rosenberg ** -** $Id: backgroundsupr.cpp,v 1.11 2001/03/04 03:14:47 kevin Exp $ +** $Id: backgroundsupr.cpp,v 1.12 2001/03/04 22:30:19 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -48,27 +48,14 @@ IMPLEMENT_DYNAMIC_CLASS(BackgroundSupervisor, wxEvtHandler) BEGIN_EVENT_TABLE(BackgroundSupervisor, BackgroundSupervisor) -EVT_MENU(MSG_BACKGROUND_SUPERVISOR_CANCEL, BackgroundSupervisor::OnCancel) -EVT_MENU(MSG_WORKER_THREAD_FAIL, BackgroundSupervisor::OnWorkerFail) -EVT_MENU(MSG_WORKER_THREAD_DONE, BackgroundSupervisor::OnWorkerDone) -EVT_MENU(MSG_WORKER_THREAD_UNIT_TICK, BackgroundSupervisor::OnWorkerUnitTick) -EVT_MENU(MSG_DOCUMENT_ACK_REMOVE, BackgroundSupervisor::OnAckDocumentRemove) END_EVENT_TABLE() -// Static function -void -BackgroundSupervisor::cancelSupervisor (BackgroundSupervisor* pSupervisor) -{ - wxCommandEvent cancelEvent (wxEVT_COMMAND_MENU_SELECTED, MSG_BACKGROUND_SUPERVISOR_CANCEL); - wxPostEvent (pSupervisor, cancelEvent); -} BackgroundSupervisor::BackgroundSupervisor (SupervisorThread* pMyThread, wxFrame* pParentFrame, wxDocument* pDocument, const char* const pszProcessTitle, int iTotalUnits) - : m_pMyThread(pMyThread), m_pParentFrame(pParentFrame), m_pDocument(pDocument), m_strProcessTitle(pszProcessTitle), - m_iTotalUnits(iTotalUnits), m_iNumThreads(0), m_bDone(false), m_bFail(false), m_bCancelled(false), - m_pTimer(NULL), m_bBackgroundTaskAdded(false), m_bWorkersDeleted(false), - wxEvtHandler() + : wxEvtHandler(), m_pMyThread(pMyThread), m_pParentFrame(pParentFrame), m_pDocument(pDocument), m_strProcessTitle(pszProcessTitle), + m_iTotalUnits(iTotalUnits), m_iNumThreads(0), m_bDone(false), m_bFail(false), m_bCancelled(false), m_iRunning(0), + m_pTimer(NULL), m_bBackgroundTaskAdded(false), m_bWorkersDeleted(false) { m_iNumThreads = theApp->getNumberCPU(); // ++m_iNumThreads; @@ -90,7 +77,6 @@ BackgroundSupervisor::~BackgroundSupervisor() while (m_bBackgroundTaskAdded) { m_pMyThread->Sleep(50); - ProcessPendingEvents(); } delete m_pTimer; @@ -110,7 +96,6 @@ BackgroundSupervisor::deleteWorkers() while (m_iRunning > 0) { m_pMyThread->Sleep(50); - ProcessPendingEvents(); } m_iRunning = 0; m_bWorkersDeleted = true; @@ -166,21 +151,21 @@ BackgroundSupervisor::start() } void -BackgroundSupervisor::OnCancel(wxCommandEvent& event) +BackgroundSupervisor::onCancel() { m_bCancelled = true; m_bDone = true; - deleteWorkers(); } void -BackgroundSupervisor::OnAckDocumentRemove(wxCommandEvent& event) +BackgroundSupervisor::onAckDocumentRemove() { m_bBackgroundTaskAdded = false; } + void -BackgroundSupervisor::OnWorkerUnitTick (wxCommandEvent& event) +BackgroundSupervisor::onWorkerUnitTick () { ++m_iUnitsDone; @@ -196,8 +181,11 @@ BackgroundSupervisor::OnWorkerUnitTick (wxCommandEvent& event) } void -BackgroundSupervisor::OnWorkerDone (wxCommandEvent& event) +BackgroundSupervisor::onWorkerDone (int iThread) { + wxCriticalSection critsectDone; + critsectDone.Enter(); + m_iRunning--; wxASSERT (m_iRunning >= 0); @@ -210,22 +198,19 @@ BackgroundSupervisor::OnWorkerDone (wxCommandEvent& event) wxPostEvent( theApp->getMainFrame(), eventLog ); // send log event } #endif - if (m_iRunning <= 0 && ! m_bCancelled) { - deleteWorkers(); - onDone(); - } + + critsectDone.Leave(); } void -BackgroundSupervisor::OnWorkerFail (wxCommandEvent& event) +BackgroundSupervisor::onWorkerFail (int iThread, std::string strFailMessage) { m_iRunning--; wxCommandEvent eventLog( wxEVT_COMMAND_MENU_SELECTED, MAINMENU_LOG_EVENT ); - eventLog.SetString( event.GetString() ); + eventLog.SetString( strFailMessage.c_str() ); wxPostEvent( theApp->getMainFrame(), eventLog ); // send log event - wxCommandEvent dummy; - OnCancel(dummy); + onCancel(); } #endif // HAVE_WXTHREADS