getfem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getfem-commits] r4548 - /trunk/getfem/src/getfem/dal_singleton.h


From: andriy . andreykiv
Subject: [Getfem-commits] r4548 - /trunk/getfem/src/getfem/dal_singleton.h
Date: Wed, 19 Mar 2014 17:24:11 -0000

Author: andrico
Date: Wed Mar 19 18:24:10 2014
New Revision: 4548

URL: http://svn.gna.org/viewcvs/getfem?rev=4548&view=rev
Log:
removed interdependence of static members initialization in singletons

Modified:
    trunk/getfem/src/getfem/dal_singleton.h

Modified: trunk/getfem/src/getfem/dal_singleton.h
URL: 
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem/dal_singleton.h?rev=4548&r1=4547&r2=4548&view=diff
==============================================================================
--- trunk/getfem/src/getfem/dal_singleton.h     (original)
+++ trunk/getfem/src/getfem/dal_singleton.h     Wed Mar 19 18:24:10 2014
@@ -80,13 +80,23 @@
     singletons_manager();
   };
 
-  template <typename T, int LEV> class singleton_instance : public 
singleton_instance_base {
+
+
+
+  template <typename T, int LEV> class singleton_instance : public 
singleton_instance_base 
+  {
+    static getfem::omp_distribute<T*>* instance_;
+    static getfem::omp_distribute<T*>* omp_distro_pointer()
+    {
+      static getfem::omp_distribute<T*>* pointer = new 
getfem::omp_distribute<T*>( );
+      return pointer;
+    }
+    static T*& instance_pointer() { return omp_distro_pointer( )->thrd_cast(); 
}
+    static T*& instance_pointer(int ithread) { return (*omp_distro_pointer( 
))(ithread);}
+
   public:
-    static getfem::omp_distribute<T*>* instance_;
 
-    static T*& instance_pointer() { return instance_->thrd_cast(); }
-
-    static T*& instance_pointer(int ithread) { return (*instance_)(ithread);}
+    singleton_instance() {}
 
     /** Instance from the current thread*/
     inline static T& instance() 
@@ -100,7 +110,8 @@
     }
 
     /**Instance from thread ithread*/
-    inline static T& instance(int ithread) { 
+    inline static T& instance(int ithread) 
+    { 
       T*& tinstance_ = instance_pointer(ithread);
       if (!tinstance_) {
         tinstance_ = new T();
@@ -111,13 +122,17 @@
 
     int level() { return LEV; }
 
-    singleton_instance() {}
-
     ~singleton_instance() 
     {
-      if (instance_) {
-        for(size_t i=0;i<getfem::num_threads();i++){
-          if((*instance_)(i)){delete (*instance_)(i); (*instance_)(i) = 0;}
+      if (instance_) 
+      {
+        for(size_t i=0;i<getfem::num_threads();i++)
+        {
+          if((*instance_)(i)) 
+          { 
+            delete (*instance_)(i); 
+            (*instance_)(i) = 0; 
+          }
         } 
       }
       delete instance_; instance_=0;
@@ -159,7 +174,8 @@
   };
 
   template <typename T, int LEV> 
-  getfem::omp_distribute<T*>* singleton_instance<T,LEV>::instance_= new 
getfem::omp_distribute<T*>;
+  getfem::omp_distribute<T*>* singleton_instance<T,LEV>::instance_
+                        = singleton_instance<T,LEV>::omp_distro_pointer();
 }
 
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]