[Avida-SVN] r3577 - in development/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Wed Dec 23 13:47:23 PST 2009
Author: beckma24
Date: 2009-12-23 16:47:22 -0500 (Wed, 23 Dec 2009)
New Revision: 3577
Modified:
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
Log:
Added cHardwareCPU::InterruptThread that is called to start an interrupt.
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2009-12-23 20:02:33 UTC (rev 3576)
+++ development/source/cpu/cHardwareBase.h 2009-12-23 21:47:22 UTC (rev 3577)
@@ -89,7 +89,9 @@
static const unsigned int MASKOFF_LOWEST8 = 0xFFFFFF00;
static const unsigned int MASKOFF_LOWEST4 = 0xFFFFFFF0;
-
+ // interrupt types
+ enum interruptTypes {MSG_INTERRUPT = 0, MOVE_INTERRUPT};
+
cHardwareBase(); // @not_implemented
cHardwareBase(const cHardwareBase&); // @not_implemented
cHardwareBase& operator=(const cHardwareBase&); // @not_implemented
@@ -255,6 +257,9 @@
int TriggerMutations_ScopeGlobal(cAvidaContext& ctx, const cMutation* cur_mut,
cGenome& target_memory, cHeadCPU& cur_head, const double rate);
+ // interrupt current thread
+ void InterruptThread(int interruptType) {;}
+
private:
void checkImplicitRepro(cAvidaContext& ctx, bool exec_last_inst = false);
};
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2009-12-23 20:02:33 UTC (rev 3576)
+++ development/source/cpu/cHardwareCPU.cc 2009-12-23 21:47:22 UTC (rev 3577)
@@ -1349,7 +1349,83 @@
return true;
}
+bool cHardwareCPU::InterruptThread(int interruptType) {
+ //Will interrupt be successful? i.e. is head instuction present?
+ cString handlerHeadInstructionString;
+
+ switch (interruptType) {
+ case MSG_INTERRUPT: {
+ int messageType = GetOrganism()->PeekAtNextMessageType();
+ if(messageType == 0) {
+ handlerHeadInstructionString.Set("msg-handler");
+ } else {
+ handlerHeadInstructionString.Set("msg-handler-type%d", messageType);
+ }
+
+ // if(initializeInterruptState(msgHandlerString)) {
+ // IP().Retreat();
+ // Inst_RetrieveMessage(m_world->GetDefaultContext());
+ // IP().Advance();
+ // }
+ break;
+ }
+ case MOVE_INTERRUPT:
+ // if(initializeInterruptState("moved-handler")) {
+ // ; // perform movement interrupt initialization here
+ // }
+ break;
+ default:
+ cerr << "Unknown intrerrupt type " << interruptType << " Exitting.\n\n";
+ exit(-1);
+ break;
+ }
+
+ const cInstruction label_inst = GetInstSet().GetInst(handlerHeadInstructionString);
+ cHeadCPU search_head(IP());
+ int start_pos = search_head.GetPosition();
+ search_head++;
+
+ while (start_pos != search_head.GetPosition()) {
+ if (search_head.GetInst() == label_inst) { // found handlerHeadInstructionString
+ search_head++; // one instruction past instruction
+ }
+ }
+
+ if(start_pos == search_head.GetPosition()) {
+ return false; // no instruction denoting start of interrupt handler
+ }
+
+
+ // thread stuff
+ const int num_threads = m_threads.GetSize();
+ if (num_threads == m_world->GetConfig().MAX_CPU_THREADS.Get()) return false;
+
+ // Make room for the new thread.
+ m_threads.Resize(num_threads + 1);
+
+ // Find the first free bit in m_thread_id_chart to determine the new
+ // thread id.
+ int new_id = 0;
+ while ( (m_thread_id_chart >> new_id) & 1 == 1) new_id++;
+ m_threads[num_threads].SetID(new_id);
+ m_thread_id_chart |= (1 << new_id);
+
+
+ // interrupt stuff
+ m_threads[num_threads].Reset(this,new_id);
+
+ m_cur_thread = num_threads;
+ // move all heads to one past beginning
+
+ // set all heads to same spot
+ for(int i = 0; i < NUM_HEADS; i++) {
+ GetHead(i,new_id).Set(search_head.GetPosition());
+ }
+ return true;
+}
+
+
bool cHardwareCPU::KillThread()
{
// Make sure that there is always at least one thread...
@@ -1372,6 +1448,8 @@
m_threads.Resize(m_threads.GetSize() - 1);
if (m_cur_thread > kill_thread) m_cur_thread--;
+
+ //TODO: it interrupt enabled and more messages to process then reinterrupt
return true;
}
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2009-12-23 20:02:33 UTC (rev 3576)
+++ development/source/cpu/cHardwareCPU.h 2009-12-23 21:47:22 UTC (rev 3577)
@@ -119,7 +119,6 @@
int GetPromoterInstExecuted() { return m_promoter_inst_executed; }
void IncPromoterInstExecuted() { m_promoter_inst_executed++; }
void ResetPromoterInstExecuted() { m_promoter_inst_executed = 0; }
-
};
@@ -208,6 +207,7 @@
// -------- Thread Manipulation -------
bool ForkThread(); // Adds a new thread based off of m_cur_thread.
+ bool InterruptThread(int interruptType); // Create a new thread that interrupts the current thread
bool KillThread(); // Kill the current thread!
// ---------- Instruction Helpers -----------
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2009-12-23 20:02:33 UTC (rev 3576)
+++ development/source/main/cOrganism.cc 2009-12-23 21:47:22 UTC (rev 3577)
@@ -895,6 +895,9 @@
msg.SetReceiver(this);
m_msg->received.push_back(msg);
+
+ //TODO: perform context switch
+ // need config option for depth of saved context stack
}
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2009-12-23 20:02:33 UTC (rev 3576)
+++ development/source/main/cOrganism.h 2009-12-23 21:47:22 UTC (rev 3577)
@@ -405,6 +405,7 @@
const message_list_type& GetSentMessages() { InitMessaging(); return m_msg->sent; }
//! Use at your own rish; clear all the message buffers.
void FlushMessageBuffers() { InitMessaging(); m_msg->sent.clear(); m_msg->received.clear(); }
+ int PeekAtNextMessageType() { InitMessaging(); return m_msg->received.front().GetMessageType(); }
private:
/*! Contains all the different data structures needed to support messaging within
More information about the Avida-cvs
mailing list