00001 // emacs mode line -*- mode: c++; tab-width: 4 -*- 00002 #include "charm++.h" 00003 #include "msa-distArray.h" 00004 00005 MSA_Listener::~MSA_Listener() {} 00006 00007 MSA_Listeners::MSA_Listeners() {} 00008 00010 void MSA_Listeners::add(MSA_Listener *l) { 00011 l->add(); 00012 listeners.push_back(l); 00013 } 00014 00016 void MSA_Listeners::signal(unsigned int pageNo) { 00017 if (listeners.size()>0) { 00018 for (unsigned int i=0;i<listeners.size();i++) 00019 listeners[i]->signal(pageNo); 00020 listeners.resize(0); 00021 } 00022 } 00023 00024 MSA_Listeners::~MSA_Listeners() { 00025 if (listeners.size()!=0) 00026 CkAbort("Tried to delete MSA_Listeners before signaling!"); 00027 } 00028 00030 void MSA_Thread_Listener::add(void) { 00031 count++; 00032 } 00033 00035 void MSA_Thread_Listener::suspend(void) { 00036 bool verbose=false; 00037 if (count>0) { 00038 thread=CthSelf(); 00039 if (verbose) CkPrintf("Thread %p suspending for %d signals\n", 00040 CthSelf(),count); 00041 CthSuspend(); 00042 if (verbose) CkPrintf("Thread %p resumed\n",CthSelf()); 00043 } 00044 } 00045 00046 void MSA_Thread_Listener::signal(unsigned int pageNo) 00047 { 00048 count--; 00049 if (count<0) CkAbort("MSA_Thread_Listener signaled more times than added!"); 00050 if (count==0) { /* now ready to resume thread (if needed) */ 00051 if (thread!=0) { 00052 CthAwaken(thread); 00053 thread=0; 00054 } 00055 } 00056 } 00057 00058 #include "msa.def.h"