[Avida-SVN] r3013 - in branches/interrupt/source: actions cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Mon Dec 8 12:55:25 PST 2008
Author: beckma24
Date: 2008-12-08 15:55:25 -0500 (Mon, 08 Dec 2008)
New Revision: 3013
Modified:
branches/interrupt/source/actions/PrintActions.cc
branches/interrupt/source/cpu/cHardwareCPU.cc
branches/interrupt/source/cpu/cHardwareCPU.h
branches/interrupt/source/cpu/cOrganismThread.h
branches/interrupt/source/main/cOrganism.cc
branches/interrupt/source/main/cPopulation.cc
branches/interrupt/source/main/cPopulation.h
Log:
fixed interrupt bug caused by use a reference copy. Now messaging interrupts are atomic.
Modified: branches/interrupt/source/actions/PrintActions.cc
===================================================================
--- branches/interrupt/source/actions/PrintActions.cc 2008-12-08 18:43:36 UTC (rev 3012)
+++ branches/interrupt/source/actions/PrintActions.cc 2008-12-08 20:55:25 UTC (rev 3013)
@@ -2534,7 +2534,7 @@
static const cString GetDescription() { return "No Arguments"; }
void Process(cAvidaContext& ctx) {
- m_world->GetPopulation().PrintDemesTotalAvgEnergy();
+ m_world->GetPopulation().PrintDemeTotalAvgEnergy();
}
};
Modified: branches/interrupt/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/interrupt/source/cpu/cHardwareCPU.cc 2008-12-08 18:43:36 UTC (rev 3012)
+++ branches/interrupt/source/cpu/cHardwareCPU.cc 2008-12-08 20:55:25 UTC (rev 3013)
@@ -119,6 +119,7 @@
// push interrupt arguments into registers, i.e. MSG contents are placed in BX & CX, nothing for movement
void cLocalThread::initializeInterruptState(const cString& handlerHeadInstructionString) {
+
for (int i = 0; i < NUM_REGISTERS; i++)
hardware->GetRegister(i) = 0;
@@ -130,7 +131,7 @@
//Jump all heads 1 instruction passed MSG_received_handler_START
- cInstruction label_inst = hardware->GetInstSet().GetInst(handlerHeadInstructionString); //cStringUtil::Stringf("MSG_received_handler_END"));
+ cInstruction label_inst = hardware->GetInstSet().GetInst(handlerHeadInstructionString);
cHeadCPU search_head(hardware->IP());
int start_pos = search_head.GetPosition();
@@ -177,7 +178,7 @@
}
else if(interrupted && interruptType == cLocalThread::INTERRUPT_COMPLETE) { // currently interrupted
if(hardware->GetOrganism()->GetReceivedBufferSize() > 0) { // more messages to process
- initializeInterruptState("MSG_received_handler_START"); // this line only affect else clause
+ initializeInterruptState("MSG_received_handler_START");
hardware->Inst_RetrieveMessage(m_world->GetDefaultContext());
} else { // interrupt -> normal
interrupted = false;
@@ -1850,7 +1851,7 @@
void cHardwareCPU::InheritState(cHardwareBase& in_hardware)
{
m_epigenetic_state = true;
- cHardwareCPU& in_h = (cHardwareCPU&)in_hardware;
+ const cHardwareCPU& in_h = (cHardwareCPU&)in_hardware;
const cLocalThread& thread = in_h.GetThread(in_h.GetCurThread());
for (int i=0; i<NUM_REGISTERS; i++) {
m_epigenetic_saved_reg[i] = thread.reg[i];
@@ -5208,6 +5209,8 @@
where the label field of sent message is from register ?BX?, and the data field
is from register ~?BX?.
*/
+// If INTERRUPT_ENABLED then with function will cause the MSG receiver to jump inside its interrupt handler,
+// and call Inst_RetrieveMessage which eats a NOP if one exists
bool cHardwareCPU::Inst_SendMessage(cAvidaContext& ctx)
{
const int label_reg = FindModifiedRegister(REG_BX);
Modified: branches/interrupt/source/cpu/cHardwareCPU.h
===================================================================
--- branches/interrupt/source/cpu/cHardwareCPU.h 2008-12-08 18:43:36 UTC (rev 3012)
+++ branches/interrupt/source/cpu/cHardwareCPU.h 2008-12-08 20:55:25 UTC (rev 3013)
@@ -337,7 +337,9 @@
int GetNumThreads() const { return m_threads.GetSize(); }
int GetCurThread() const { return m_cur_thread; }
int GetCurThreadID() const { return m_threads[m_cur_thread].GetID(); }
- const cLocalThread& GetThread(int _index) const { return m_threads[_index]; }
+ const cLocalThread& GetThread(int _index) const { return m_threads[_index]; }
+ cLocalThread* GetThread(int _index) { return &m_threads[_index]; }
+
// -------- Parasite Stuff --------
bool InjectHost(const cCodeLabel& in_label, const cGenome& injection);
Modified: branches/interrupt/source/cpu/cOrganismThread.h
===================================================================
--- branches/interrupt/source/cpu/cOrganismThread.h 2008-12-08 18:43:36 UTC (rev 3012)
+++ branches/interrupt/source/cpu/cOrganismThread.h 2008-12-08 20:55:25 UTC (rev 3013)
@@ -25,7 +25,7 @@
int GetID() const { return m_id; }
void SetID(int in_id) { m_id = in_id; }
- bool isInterrupted() { return interrupted; }
+ bool isInterrupted() const { return interrupted; }
virtual void saveState() = 0; //!< saves thread's current state
virtual void restoreState() = 0; //!< restores thread's saved state
Modified: branches/interrupt/source/main/cOrganism.cc
===================================================================
--- branches/interrupt/source/main/cOrganism.cc 2008-12-08 18:43:36 UTC (rev 3012)
+++ branches/interrupt/source/main/cOrganism.cc 2008-12-08 20:55:25 UTC (rev 3013)
@@ -697,9 +697,9 @@
m_msg->received.push_back(msg);
- cLocalThread currentThread = static_cast<cHardwareCPU*>(GetHardware(false))->GetThread(GetHardware(true)->GetCurThread());
- if(m_world->GetConfig().INTERRUPT_ENABLED.Get() && currentThread.isInterrupted() == false) {
- currentThread.interruptContextSwitch(cLocalThread::MSG_INTERRUPT);
+ cLocalThread* currentThread = static_cast<cHardwareCPU*>(m_hardware)->GetThread(GetHardware(true)->GetCurThread());
+ if(m_world->GetConfig().INTERRUPT_ENABLED.Get() && currentThread->isInterrupted() == false) {
+ currentThread->interruptContextSwitch(cLocalThread::MSG_INTERRUPT);
}
// else msg gets added to msg queue and will cause interrupt after current interrupt is processed
}
Modified: branches/interrupt/source/main/cPopulation.cc
===================================================================
--- branches/interrupt/source/main/cPopulation.cc 2008-12-08 18:43:36 UTC (rev 3012)
+++ branches/interrupt/source/main/cPopulation.cc 2008-12-08 20:55:25 UTC (rev 3013)
@@ -2586,7 +2586,7 @@
}
-void cPopulation::PrintDemesTotalAvgEnergy() {
+void cPopulation::PrintDemeTotalAvgEnergy() {
cStats& stats = m_world->GetStats();
const int num_demes = deme_array.GetSize();
cDataFile & df_fit = m_world->GetDataFile("deme_totalAvgEnergy.dat");
Modified: branches/interrupt/source/main/cPopulation.h
===================================================================
--- branches/interrupt/source/main/cPopulation.h 2008-12-08 18:43:36 UTC (rev 3012)
+++ branches/interrupt/source/main/cPopulation.h 2008-12-08 20:55:25 UTC (rev 3013)
@@ -229,7 +229,7 @@
void PrintDemeAllStats();
void PrintDemeTestamentStats(const cString& filename);
void PrintDemeDonor();
- void PrintDemesTotalAvgEnergy();
+ void PrintDemeTotalAvgEnergy();
void PrintDemeFitness();
void PrintDemeGestationTime();
void PrintDemeInstructions();
More information about the Avida-cvs
mailing list