Added "simpler" (?) interface for libraries to inherit from and use.
authorOrion Lawlor <olawlor@acm.org>
Fri, 17 May 2002 18:27:44 +0000 (18:27 +0000)
committerOrion Lawlor <olawlor@acm.org>
Fri, 17 May 2002 18:27:44 +0000 (18:27 +0000)
src/libs/ck-libs/tcharm/tcharm.C
src/libs/ck-libs/tcharm/tcharm.h

index 72c4389181ca1c86c2de65d07a63454526afbba8..8d570b96365f2b95a55077b27b823bcde877dee7 100644 (file)
@@ -291,6 +291,18 @@ static void TCharmBuildThreads(TCharmInitMsg *msg,TCharmSetupCookie &cook)
        cook.setThreads(id,nElem);
 }
 
+/****** TcharmClient ******/
+void TCharmClient1D::ckJustMigrated(void) {
+  ArrayElement1D::ckJustMigrated();
+  tcharmClientInit();
+}
+
+void TCharmClient1D::pup(PUP::er &p) {
+  ArrayElement1D::pup(p);
+  p|threadProxy;
+}
+
+
 /****** Readonlys *****/
 CkVec<TCpupReadonlyGlobal> TCharmReadonlys::entries;
 void TCharmReadonlys::add(TCpupReadonlyGlobal fn)
index ee4df9353017e27d0affdafba4e81e0a62cf445a..cfd4da1ad7f810565182e7e98682576013590f27 100644 (file)
@@ -187,7 +187,43 @@ class TCharm: public ArrayElement1D
        }
 };
 
-//Controls array startup, ready, run and shutdown
+//A simple client array that can be bound to a tcharm array:
+class TCharmClient1D : public ArrayElement1D {
+  CProxy_TCharm threadProxy; //Proxy for our bound TCharm array
+ protected:
+  TCharm *thread; //The actual TCharm object we're bound to.
+  
+  //Clients need to override this function to set their
+  // thread-private variables.  You usually use something like:
+  //  CtvAccessOther(forThread,_myFooPtr)=this;
+  virtual void setupThreadPrivate(CthThread forThread) =0;
+  
+ public:
+  TCharmClient1D(const CProxy_TCharm &threadProxy_) 
+    :threadProxy(threadProxy_)
+  {
+    //Argh!  Can't call setupThreadPrivate yet, because
+    // virtual functions don't work within constructors!
+    thread=NULL;
+  }
+  TCharmClient1D(CkMigrateMessage *m) //Migration, etc. constructor
+  {
+    thread=NULL;
+  }
+  
+  //You MUST call this from your constructor:
+  inline void tcharmClientInit(void) {
+    thread=threadProxy[thisIndex].ckLocal();  
+    if (thread==NULL) CkAbort("FEM can't locate its thread!\n");
+    setupThreadPrivate(thread->getThread());
+  }
+  
+  virtual void ckJustMigrated(void);
+  virtual void pup(PUP::er &p);
+};
+
+
+//TCharm internal class: Controls array startup, ready, run and shutdown
 class TCharmCoordinator {
        static int nArrays; //Total number of running thread arrays
        static TCharmCoordinator *head; //List of coordinators