Index: /trunk/SophyaLib/BaseTools/ndatablock.h
===================================================================
--- /trunk/SophyaLib/BaseTools/ndatablock.h	(revision 3212)
+++ /trunk/SophyaLib/BaseTools/ndatablock.h	(revision 3213)
@@ -174,5 +174,5 @@
   static size_t NallocData; //!< DEBUG: number of allocations (all type<T> classes)
   static size_t NallocSRef; //!< DEBUG: number of references (all type<T> classes)
-  static ThSafeOp* gThsop;  //!< DEBUG: for thread safe operation 
+  static ThSafeOp* gThsop;  //!< Mutex For thread safe operation 
 
   size_t       mSz;      //!< size of data structure
Index: /trunk/SophyaLib/BaseTools/segdatablock.h
===================================================================
--- /trunk/SophyaLib/BaseTools/segdatablock.h	(revision 3212)
+++ /trunk/SophyaLib/BaseTools/segdatablock.h	(revision 3213)
@@ -13,4 +13,6 @@
 #include <iomanip>
 #include <typeinfo>
+
+#include "thsafeop.h"  //  for ThreadSafe operations (Ref.Count/Share) 
 
 /*!
@@ -67,4 +69,5 @@
   {
     mSRef = NULL;
+    if (gThsop == NULL) gThsop = new ThSafeOp;
     SetSize(segsz, nbseg);
   }
@@ -72,6 +75,8 @@
   SegDataBlock(const SegDataBlock<T>& a)
   {
+    gThsop->lock();   //  (ThreadSafe) - Start of atomic operation 
     mSRef = a.mSRef;
     mSRef->nref++;
+    gThsop->unlock();   //  (ThreadSafe) - End of atomic operation
   }
   //! copy constructor with specification of flags for data sharing and element value copy
@@ -79,6 +84,8 @@
   {
     if (share) {
+      gThsop->lock();   //  (ThreadSafe) - Start of atomic operation 
       mSRef = a.mSRef;
       mSRef->nref++;
+      gThsop->unlock();   //  (ThreadSafe) - End of atomic operation
     }
     else {
@@ -90,8 +97,11 @@
   SegDataBlock(const SegDBInterface<T>& a)
   {
+    if (gThsop == NULL) gThsop = new ThSafeOp;
     SegDataBlock<T> * sdb = dynamic_cast< SegDataBlock<T> *>(&a);
     if (sdb != NULL) { 
+      gThsop->lock();   //  (ThreadSafe) - Start of atomic operation 
       mSRef = sdb->mSRef;
       mSRef->nref++;
+      gThsop->unlock();   //  (ThreadSafe) - End of atomic operation
     }
     else Clone(a, true);
@@ -101,13 +111,17 @@
   {
     //DEL    cout << " DEBUG-~SegDataBlock() " << hex << mSRef << dec << " NRef()= " << NRef() << endl;
-     Delete();
-  }
-
-
-  //! Adds one segment to the data structure - returns the pointer to the allocated segment.
+    gThsop->lock();   //  (ThreadSafe) - Start of atomic operation 
+    Delete();
+    gThsop->unlock();   //  (ThreadSafe) - End of atomic operation
+  }
+
+
+  //! Adds one segment to the data structure - returns the number of allocated segments.
   virtual size_t Extend()
   {
     T * p = new T[mSRef->segsize];
+    gThsop->lock();   //  (ThreadSafe) - Start of atomic operation 
     mSRef->dseg.push_back(p);
+    gThsop->unlock();   //  (ThreadSafe) - End of atomic operation
     return( mSRef->dseg.size());
   }
@@ -117,4 +131,5 @@
   virtual void SetSize(size_t segsz, size_t nbseg=0)
   {
+    gThsop->lock();   //  (ThreadSafe) - Start of atomic operation 
     Delete();
     mSRef = new SDREF;
@@ -122,12 +137,15 @@
     mSRef->segsize = segsz;
     mSRef->dsid = AnyDataObj::getUniqueId();
-    for(size_t k=0; k<nbseg; k++) Extend();
+    for(size_t k=0; k<nbseg; k++) Extend_P();
+    gThsop->unlock();   //  (ThreadSafe) - End of atomic operation
   }
 //! Shares the data between two SegDataBlock objects
   void Share(const SegDataBlock<T>& a)
   {
+    gThsop->lock();   //  (ThreadSafe) - Start of atomic operation 
     Delete();
     mSRef = a.mSRef;
     mSRef->nref++;
+    gThsop->unlock();   //  (ThreadSafe) - End of atomic operation
   }
 
@@ -135,8 +153,10 @@
   void Clone(const SegDBInterface<T> & a, bool cpval=true)
   {
+    gThsop->lock();   //  (ThreadSafe) - Start of atomic operation 
     Delete();
     mSRef = new SDREF;
     mSRef->nref = 1;
     mSRef->segsize = a.SegmentSize();
+    gThsop->unlock();   //  (ThreadSafe) - End of atomic operation
     for(size_t k=0; k<a.NbSegments(); k++) {
       Extend();
@@ -230,4 +250,5 @@
 
 protected:
+  //! NON-thread safe: Decrement the number of reference counts, and free the memory if NRef=0
   void Delete() 
   {
@@ -243,4 +264,12 @@
     mSRef = NULL;
   }
+  //! NON-thread safe, version of Extend() : Adds one segment to the data structure 
+  size_t Extend_P()
+  {
+    T * p = new T[mSRef->segsize];
+    mSRef->dseg.push_back(p);
+    return( mSRef->dseg.size());
+  }
+
   /*! \cond 
     SDREF structure for reference management - for internal use by SegDataBlock
@@ -254,5 +283,9 @@
   /*! \endcond */
   SDREF *  mSRef;    //!< SDREF structure for reference sharing
+
+  static ThSafeOp* gThsop;  //!< Mutex for thread safe operation 
 };
+
+template <class T> ThSafeOp* SegDataBlock<T>::gThsop  = NULL;  // static member initialized to NULL
 
 //! Definition of operator \<\< for ascii formatted output of SegDataBlock
Index: /trunk/SophyaLib/BaseTools/sophyainit.cc
===================================================================
--- /trunk/SophyaLib/BaseTools/sophyainit.cc	(revision 3212)
+++ /trunk/SophyaLib/BaseTools/sophyainit.cc	(revision 3213)
@@ -27,4 +27,8 @@
 // Module version number - 2.0 , Jul 2006
 // Module version number - 2.02 , Fev07 Ajout NDataBlock::RenewObjId()
+// Module version number - 2.1 ,  Avr07 
+//  - Nettoyage machdefs_mkmf.h 
+//  - Ajout classe ThSafeOp ---> NDataBlock<T> Sw/SegDataBlock<T> ThreadSafe
+//     
 #define MOD_VERS   2.02
 
@@ -58,12 +62,4 @@
   ModListP = new map<string, double>;
   
-
-  #ifdef xx__mac__
-  //InitToolBox();
-  //SIOUXSettings.initializeTB = FALSE;
-  SIOUXSettings.autocloseonquit = FALSE;
-  SIOUXSettings.asktosaveonclose = FALSE;
-  SIOUXSettings.showstatusline = TRUE;
-  #endif
 
   // Initialisation des mecanismes PPF I/O 
@@ -206,7 +202,7 @@
   #ifdef __IBMCPP__
   #ifdef SO_ARCH64
-  compiler = const_cast<char *>("IBM-xlC ") ;
+  compiler = const_cast<char *>("IBM-xlC (-q64)") ;
   #else
-  compiler = const_cast<char *>("IBM-xlC (-q64)") ;
+  compiler = const_cast<char *>("IBM-xlC") ;
   #endif
   #endif
Index: /trunk/SophyaLib/BaseTools/sversion.h
===================================================================
--- /trunk/SophyaLib/BaseTools/sversion.h	(revision 3212)
+++ /trunk/SophyaLib/BaseTools/sversion.h	(revision 3213)
@@ -3,6 +3,6 @@
 
 #define SOPHYA_VERSION   2.1
-#define SOPHYA_REVISION  20
-#define SOPHYA_TAG       "V_Jan2007"
+#define SOPHYA_REVISION  30
+#define SOPHYA_TAG       "V_Avr2007"
 
 #endif
Index: /trunk/SophyaLib/BaseTools/swsegdb.h
===================================================================
--- /trunk/SophyaLib/BaseTools/swsegdb.h	(revision 3212)
+++ /trunk/SophyaLib/BaseTools/swsegdb.h	(revision 3213)
@@ -69,6 +69,8 @@
     SetSize(segsz, swpos.size());
     SetSwapper(dsw);
+    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation 
     mSRef->swp = swpos;
     for(size_t k=0; k<mSRef->fgwp.size(); k++)  mSRef->fgwp[k] = true; 
+    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
     }
   //! Constructor - optional specification of segment size and number of segments
@@ -82,16 +84,25 @@
   SwSegDataBlock(const SwSegDataBlock<T>& a)
   {
+    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation 
     mSRef = a.mSRef;
     mSRef->nref++;
+    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
   }
 
   //! Destructor. The memory is freed when the last object referencing the data segment is destroyed
-  virtual ~SwSegDataBlock() { Delete(); }
+  virtual ~SwSegDataBlock() 
+  { 
+    Delete(); 
+  }
   //! Adds one segment to the data structure - returns the pointer to the allocated segment.
   virtual size_t Extend() 
   {
+    size_t rs = 0;
+    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation 
     mSRef->swp.push_back(0);
     mSRef->fgwp.push_back(false);
-    return mSRef->swp.size();
+    rs = mSRef->swp.size();
+    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
+    return rs;
   }
   /*! \brief Changes the data segment size and reallocates the memory segments
@@ -102,4 +113,5 @@
   {
     Delete();
+    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation 
     mSRef = new SWSDREF;
     mSRef->nref = 1;
@@ -114,4 +126,5 @@
     }
     mSRef->swapper = NULL;
+    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
   }
 
@@ -120,6 +133,8 @@
   {
     if (mSRef == NULL) return;
+    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation 
     if (mSRef->swapper) delete mSRef->swapper;  
     mSRef->swapper = dsw.Clone();
+    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
   }
 
@@ -133,13 +148,21 @@
   virtual T* GetSegment(size_t k) 
   {
+    T* rs = NULL;
+    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation 
     getSeg(k);
     mSRef->fgcstbuff = false;
-    return mSRef->buff;
+    rs = mSRef->buff;
+    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
+    return rs;
   }
   //! Return the const (read-only) pointer to data segment \b k         
   virtual T const * GetCstSegment(size_t k) const 
   {
+    T const * rs = NULL;
+    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation 
     if (getSeg(k))  mSRef->fgcstbuff = true;
-    return mSRef->buff;
+    rs = mSRef->buff;
+    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
+    return rs;    
   }
 
@@ -148,6 +171,8 @@
   {
     Delete();
+    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation 
     mSRef = a.mSRef;
     mSRef->nref++;
+    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
     return *this;
   }
@@ -156,4 +181,5 @@
   void SwapOutBuffer() const
   {
+    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation 
     if ((mSRef->bidx >= 0) && !mSRef->fgcstbuff) {
       int_8 nswp = mSRef->swapper->WriteToSwap(mSRef->buff, mSRef->segsize, mSRef->bidx, 
@@ -164,4 +190,5 @@
       mSRef->fgcstbuff = true;  
    }
+    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
   }
   //! Return the position tag (swap position) table, after call to SwapOutBuffer()
@@ -180,8 +207,14 @@
   {
     if (mSRef == NULL) return;
+    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation 
     mSRef->nref--;
-    if (mSRef->nref > 0)  { mSRef = NULL; return; }
+    if (mSRef->nref > 0)  { 
+      mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
+      mSRef = NULL; 
+      return; 
+    }
     if (mSRef->swapper) delete mSRef->swapper;  
     delete[] mSRef->buff;
+    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
     delete mSRef;
     mSRef = NULL;  
@@ -214,7 +247,9 @@
     mutable bool fgcstbuff;            // true : this is a constant T * buff<
     DataSwapperInterface<T> * swapper;   // Data swapper
+    ThSafeOp gThsop;         // Mutex for thread safe operation one / SWSDREF struct 
   } SWSDREF;
   //! \endcond
-  SWSDREF *  mSRef;    // SWSDREF structure for reference sharing
+  SWSDREF *  mSRef;    //!< SWSDREF structure for reference sharing
+
 };
 
