** This is part of the CTSim program
** Copyright (C) 1983-2001 Kevin Rosenberg
**
-** $Id: backgroundsupr.cpp,v 1.12 2001/03/04 22:30:19 kevin Exp $
+** $Id: backgroundsupr.cpp,v 1.13 2001/03/05 17:26:46 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
-BackgroundSupervisor::BackgroundSupervisor (SupervisorThread* pMyThread, wxFrame* pParentFrame, wxDocument* pDocument, const char* const pszProcessTitle, int iTotalUnits)
+BackgroundSupervisor::BackgroundSupervisor (SupervisorThread* pMyThread, wxFrame* pParentFrame, BackgroundProcessingDocument* pDocument, const char* const pszProcessTitle, int iTotalUnits)
: 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_pTimer(NULL), m_bWorkersDeleted(false)
{
m_iNumThreads = theApp->getNumberCPU();
// ++m_iNumThreads;
BackgroundSupervisor::~BackgroundSupervisor()
{
- if (m_bBackgroundTaskAdded) {
- wxCommandEvent doneEvent (wxEVT_COMMAND_MENU_SELECTED, MSG_BACKGROUND_SUPERVISOR_REMOVE);
- doneEvent.SetClientData (this);
- wxPostEvent (theApp->getBackgroundManager(), doneEvent);
- wxPostEvent (m_pDocument, doneEvent);
- }
+ wxCommandEvent doneEvent (wxEVT_COMMAND_MENU_SELECTED, MSG_BACKGROUND_SUPERVISOR_REMOVE);
+ doneEvent.SetClientData (this);
+ wxPostEvent (theApp->getBackgroundManager(), doneEvent);
- while (m_bBackgroundTaskAdded) {
- m_pMyThread->Sleep(50);
- }
+ m_pDocument->removeBackgroundSupervisor (this);
delete m_pTimer;
}
addTaskEvent.SetInt (m_iTotalUnits);
addTaskEvent.SetClientData (this);
wxPostEvent (theApp->getBackgroundManager(), addTaskEvent);
- wxPostEvent (m_pDocument, addTaskEvent);
- m_bBackgroundTaskAdded = true;
+
+ m_pDocument->addBackgroundSupervisor (this);
m_iRunning = m_iNumThreads;
m_iUnitsDone = 0;
m_bDone = true;
}
-void
-BackgroundSupervisor::onAckDocumentRemove()
-{
- m_bBackgroundTaskAdded = false;
-}
-
void
BackgroundSupervisor::onWorkerUnitTick ()
** This is part of the CTSim program
** Copyright (C) 1983-2001 Kevin Rosenberg
**
-** $Id: backgroundsupr.h,v 1.8 2001/03/04 22:30:19 kevin Exp $
+** $Id: backgroundsupr.h,v 1.9 2001/03/05 17:26:46 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
// Pure virtual class for BackgroundSupervisor that can communication
// with BackgroundManager via messages
class BackgroundWorkerThread;
+class BackgroundProcessingDocument;
class BackgroundSupervisor : public wxEvtHandler {
private:
SupervisorThread* m_pMyThread;
wxFrame* m_pParentFrame;
- wxDocument* m_pDocument;
+ BackgroundProcessingDocument* m_pDocument;
const std::string m_strProcessTitle;
const unsigned int m_iTotalUnits;
volatile int m_iRunning;
unsigned int m_iUnitsDone;
Timer* m_pTimer;
- bool m_bBackgroundTaskAdded;
bool m_bWorkersDeleted;
typedef std::vector<BackgroundWorkerThread*> ThreadContainer;
MSG_WORKER_THREAD_FAIL = 7507, // sent by workers when they fail
};
- BackgroundSupervisor (SupervisorThread* pMyThread, wxFrame* pParentFrame, wxDocument* pDocument, const char* const pszProcessTitle,
+ BackgroundSupervisor (SupervisorThread* pMyThread, wxFrame* pParentFrame, BackgroundProcessingDocument* pDocument, const char* const pszProcessTitle,
int iTotalUnits);
BackgroundSupervisor ()
virtual void onDone() {};
virtual void onCancel();
- virtual void onAckDocumentRemove();
virtual void onWorkerFail(int iThread, std::string strFailMessage);
virtual void onWorkerUnitTick();
** This is part of the CTSim program
** Copyright (c) 1983-2001 Kevin Rosenberg
**
-** $Id: docs.cpp,v 1.32 2001/03/05 15:10:58 kevin Exp $
+** $Id: docs.cpp,v 1.33 2001/03/05 17:26:46 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
IMPLEMENT_DYNAMIC_CLASS(BackgroundProcessingDocument, wxDocument)
BEGIN_EVENT_TABLE(BackgroundProcessingDocument, wxDocument)
-#ifdef CTSIM_THREADS
-EVT_MENU(BackgroundSupervisor::MSG_BACKGROUND_SUPERVISOR_ADD, BackgroundProcessingDocument::OnAddBackground)
-EVT_MENU(BackgroundSupervisor::MSG_BACKGROUND_SUPERVISOR_REMOVE, BackgroundProcessingDocument::OnRemoveBackground)
-#endif
END_EVENT_TABLE()
-#ifdef CTSIM_TREADS
+#ifdef HAVE_WXTHREADS
void
-BackgroundProcessingDocument::OnAddBackground (wxCommandEvent& event)
+BackgroundProcessingDocument::addBackgroundSupervisor (BackgroundSupervisor* pSupervisor)
{
- BackgroundSupervisor* pSupervisor = reinterpret_cast<BackgroundSupervisor*>(event.GetClientData());
- wxASSERT (pSupervisor != NULL);
-
wxCriticalSectionLocker locker (m_criticalSection);
if (pSupervisor)
m_vecpBackgroundSupervisors.push_back (pSupervisor);
}
void
-BackgroundProcessingDocument::OnRemoveBackground (wxCommandEvent& event)
+BackgroundProcessingDocument::removeBackgroundSupervisor (BackgroundSupervisor* pSupervisor)
{
- BackgroundSupervisor* pSupervisor = reinterpret_cast<BackgroundSupervisor*>(event.GetClientData());
- wxASSERT (pSupervisor != NULL);
-
m_criticalSection.Enter();
bool bFound = false;
for (BackgroundContainer::iterator i = m_vecpBackgroundSupervisors.begin();
if (! bFound)
sys_error (ERR_SEVERE, "Could not find background task [OnRemoveBackground]");
-
- pSupervisor->onAckDocumentRemove();
}
#endif
void
BackgroundProcessingDocument::cancelRunningTasks()
{
-#ifdef CTSIM_THREADS
+#ifdef HAVE_WXTHREADS
m_criticalSection.Enter();
for (BackgroundContainer::iterator i = m_vecpBackgroundSupervisors.begin();
i != m_vecpBackgroundSupervisors.end(); i++)
** This is part of the CTSim program
** Copyright (c) 1983-2001 Kevin Rosenberg
**
-** $Id: docs.h,v 1.27 2001/03/05 15:10:58 kevin Exp $
+** $Id: docs.h,v 1.28 2001/03/05 17:26:46 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
{
private:
DECLARE_DYNAMIC_CLASS(BackgroundProcessingDocument)
-#ifdef CTSIM_THREADS
+#ifdef HAVE_WXTHREADS
typedef BackgroundSupervisor BackgroundObject;
typedef std::vector<BackgroundObject*> BackgroundContainer;
BackgroundContainer m_vecpBackgroundSupervisors;
{}
void cancelRunningTasks();
-#ifdef CTSIM_THREADS
- void OnAddBackground (wxCommandEvent& event);
- void OnRemoveBackground (wxCommandEvent& event);
+#ifdef HAVE_WXTHREADS
+ void addBackgroundSupervisor (BackgroundSupervisor* pSupervisor);
+ void removeBackgroundSupervisor (BackgroundSupervisor* pSupervisor);
#endif
DECLARE_EVENT_TABLE()
** This is part of the CTSim program
** Copyright (c) 1983-2001 Kevin Rosenberg
**
-** $Id: graph3dview.cpp,v 1.16 2001/03/04 03:14:47 kevin Exp $
+** $Id: graph3dview.cpp,v 1.17 2001/03/05 17:26:46 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
if (! GetDocument())
return;
- int nx = GetDocument()->nx();
- int ny = GetDocument()->ny();
+ unsigned int nx = GetDocument()->nx();
+ unsigned int ny = GetDocument()->ny();
const ImageFileArrayConst v = GetDocument()->getArray();
if (v != NULL && nx != 0 && ny != 0) {
double min = v[0][0];
** This is part of the CTSim program
** Copyright (C) 1983-2001 Kevin Rosenberg
**
-** $Id: threadproj.cpp,v 1.13 2001/03/04 22:30:20 kevin Exp $
+** $Id: threadproj.cpp,v 1.14 2001/03/05 17:26:46 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
projSupervisor.onDone();
projSupervisor.deleteWorkers();
- while (! projSupervisor.workersDeleted()) {
- Sleep(50);
- }
-
return reinterpret_cast<wxThread::ExitCode>(0);
}
** This is part of the CTSim program
** Copyright (C) 1983-2001 Kevin Rosenberg
**
-** $Id: threadraster.cpp,v 1.8 2001/03/04 22:30:20 kevin Exp $
+** $Id: threadraster.cpp,v 1.9 2001/03/05 17:26:46 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
if (! pRasterSupervisor->cancelled())
pRasterSupervisor->onDone();
pRasterSupervisor->deleteWorkers();
- while (! pRasterSupervisor->workersDeleted()) {
- Sleep(50);
- }
- delete pRasterSupervisor;
return reinterpret_cast<wxThread::ExitCode>(0);
}
** This is part of the CTSim program
** Copyright (C) 1983-2001 Kevin Rosenberg
**
-** $Id: threadrecon.cpp,v 1.20 2001/03/04 22:30:20 kevin Exp $
+** $Id: threadrecon.cpp,v 1.21 2001/03/05 17:26:46 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
reconSupervisor.onDone();
reconSupervisor.deleteWorkers();
- while (! reconSupervisor.workersDeleted()) {
- Sleep(50);
- }
-
return reinterpret_cast<wxThread::ExitCode>(0);
}