Don't depend on order of global variable initialization;
authorOrion Lawlor <olawlor@acm.org>
Fri, 27 Jun 2003 23:42:11 +0000 (23:42 +0000)
committerOrion Lawlor <olawlor@acm.org>
Fri, 27 Jun 2003 23:42:11 +0000 (23:42 +0000)
do initialization ourselves for initglobals.

src/libs/ck-libs/tcharm/tcharm.C

index 1cdc0d460be6f8ecce289184bc3c07ad213bd885..fa8d3a6cc131bef4e8c3d14d8eeee8aa9fca95ac 100644 (file)
@@ -365,7 +365,11 @@ CkArrayID TCHARM_Get_threads(void) {
 
 /****** Readonlys *****/
 static int tcharm_readonlygroup_created=0;
-static TCharmReadonlys initial_readonlies;
+static TCharmReadonlys *initial_readonlies=NULL;
+TCharmReadonlys &getInitialReadonlies(void) {
+       if (!initial_readonlies) initial_readonlies=new TCharmReadonlys;
+       return *initial_readonlies;
+}
 CProxy_TCharmReadonlyGroup tcharm_readonlygroup;
 
 class TCharmReadonlyGroup : public CBase_TCharmReadonlyGroup {
@@ -403,7 +407,7 @@ static void send_readonlies(TCharmReadonlys &r) {
 class TCharmReadonlyMain : public CBase_TCharmReadonlyMain {
 public:
     TCharmReadonlyMain(void) {
-       TCharmReadonlys &r=initial_readonlies;
+       TCharmReadonlys &r=getInitialReadonlies();
        int len; {PUP::sizer p; r.pupData(p); len=p.size();}
        char *data=new char[len];
        {PUP::toMem p(data); r.pupData(p);}
@@ -447,13 +451,15 @@ void TCharmReadonlys::pupAll(PUP::er &p) {
 
 CDECL void TCHARM_Readonly_globals(TCpupReadonlyGlobal fn)
 {
-       TCHARMAPI("TCHARM_Readonly_globals");
        if (!tcharm_readonlygroup_created) 
-       { // Readonly message hasn't gone out yet: just add to list
-               initial_readonlies.add(fn);
+       { // Readonly message hasn't gone out yet: just add to list.
+         // Because this routine can be called from nodesetup,
+         //  TCHARMAPI isn't safe yet.
+               getInitialReadonlies().add(fn);
        } 
        else /* tcharm_readonlygroup_created */
        { // Late addition: Broadcast our copy of the readonly data:
+               TCHARMAPI("TCHARM_Readonly_globals");
                TCharmReadonlys r; r.add(fn);
                send_readonlies(r);
        }