Changeset 3213 in Sophya for trunk/SophyaLib/BaseTools
- Timestamp:
- Apr 11, 2007, 6:12:56 PM (18 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/ndatablock.h
r3212 r3213 174 174 static size_t NallocData; //!< DEBUG: number of allocations (all type<T> classes) 175 175 static size_t NallocSRef; //!< DEBUG: number of references (all type<T> classes) 176 static ThSafeOp* gThsop; //!< DEBUG: for thread safe operation176 static ThSafeOp* gThsop; //!< Mutex For thread safe operation 177 177 178 178 size_t mSz; //!< size of data structure -
trunk/SophyaLib/BaseTools/segdatablock.h
r2884 r3213 13 13 #include <iomanip> 14 14 #include <typeinfo> 15 16 #include "thsafeop.h" // for ThreadSafe operations (Ref.Count/Share) 15 17 16 18 /*! … … 67 69 { 68 70 mSRef = NULL; 71 if (gThsop == NULL) gThsop = new ThSafeOp; 69 72 SetSize(segsz, nbseg); 70 73 } … … 72 75 SegDataBlock(const SegDataBlock<T>& a) 73 76 { 77 gThsop->lock(); // (ThreadSafe) - Start of atomic operation 74 78 mSRef = a.mSRef; 75 79 mSRef->nref++; 80 gThsop->unlock(); // (ThreadSafe) - End of atomic operation 76 81 } 77 82 //! copy constructor with specification of flags for data sharing and element value copy … … 79 84 { 80 85 if (share) { 86 gThsop->lock(); // (ThreadSafe) - Start of atomic operation 81 87 mSRef = a.mSRef; 82 88 mSRef->nref++; 89 gThsop->unlock(); // (ThreadSafe) - End of atomic operation 83 90 } 84 91 else { … … 90 97 SegDataBlock(const SegDBInterface<T>& a) 91 98 { 99 if (gThsop == NULL) gThsop = new ThSafeOp; 92 100 SegDataBlock<T> * sdb = dynamic_cast< SegDataBlock<T> *>(&a); 93 101 if (sdb != NULL) { 102 gThsop->lock(); // (ThreadSafe) - Start of atomic operation 94 103 mSRef = sdb->mSRef; 95 104 mSRef->nref++; 105 gThsop->unlock(); // (ThreadSafe) - End of atomic operation 96 106 } 97 107 else Clone(a, true); … … 101 111 { 102 112 //DEL cout << " DEBUG-~SegDataBlock() " << hex << mSRef << dec << " NRef()= " << NRef() << endl; 103 Delete(); 104 } 105 106 107 //! Adds one segment to the data structure - returns the pointer to the allocated segment. 113 gThsop->lock(); // (ThreadSafe) - Start of atomic operation 114 Delete(); 115 gThsop->unlock(); // (ThreadSafe) - End of atomic operation 116 } 117 118 119 //! Adds one segment to the data structure - returns the number of allocated segments. 108 120 virtual size_t Extend() 109 121 { 110 122 T * p = new T[mSRef->segsize]; 123 gThsop->lock(); // (ThreadSafe) - Start of atomic operation 111 124 mSRef->dseg.push_back(p); 125 gThsop->unlock(); // (ThreadSafe) - End of atomic operation 112 126 return( mSRef->dseg.size()); 113 127 } … … 117 131 virtual void SetSize(size_t segsz, size_t nbseg=0) 118 132 { 133 gThsop->lock(); // (ThreadSafe) - Start of atomic operation 119 134 Delete(); 120 135 mSRef = new SDREF; … … 122 137 mSRef->segsize = segsz; 123 138 mSRef->dsid = AnyDataObj::getUniqueId(); 124 for(size_t k=0; k<nbseg; k++) Extend(); 139 for(size_t k=0; k<nbseg; k++) Extend_P(); 140 gThsop->unlock(); // (ThreadSafe) - End of atomic operation 125 141 } 126 142 //! Shares the data between two SegDataBlock objects 127 143 void Share(const SegDataBlock<T>& a) 128 144 { 145 gThsop->lock(); // (ThreadSafe) - Start of atomic operation 129 146 Delete(); 130 147 mSRef = a.mSRef; 131 148 mSRef->nref++; 149 gThsop->unlock(); // (ThreadSafe) - End of atomic operation 132 150 } 133 151 … … 135 153 void Clone(const SegDBInterface<T> & a, bool cpval=true) 136 154 { 155 gThsop->lock(); // (ThreadSafe) - Start of atomic operation 137 156 Delete(); 138 157 mSRef = new SDREF; 139 158 mSRef->nref = 1; 140 159 mSRef->segsize = a.SegmentSize(); 160 gThsop->unlock(); // (ThreadSafe) - End of atomic operation 141 161 for(size_t k=0; k<a.NbSegments(); k++) { 142 162 Extend(); … … 230 250 231 251 protected: 252 //! NON-thread safe: Decrement the number of reference counts, and free the memory if NRef=0 232 253 void Delete() 233 254 { … … 243 264 mSRef = NULL; 244 265 } 266 //! NON-thread safe, version of Extend() : Adds one segment to the data structure 267 size_t Extend_P() 268 { 269 T * p = new T[mSRef->segsize]; 270 mSRef->dseg.push_back(p); 271 return( mSRef->dseg.size()); 272 } 273 245 274 /*! \cond 246 275 SDREF structure for reference management - for internal use by SegDataBlock … … 254 283 /*! \endcond */ 255 284 SDREF * mSRef; //!< SDREF structure for reference sharing 285 286 static ThSafeOp* gThsop; //!< Mutex for thread safe operation 256 287 }; 288 289 template <class T> ThSafeOp* SegDataBlock<T>::gThsop = NULL; // static member initialized to NULL 257 290 258 291 //! Definition of operator \<\< for ascii formatted output of SegDataBlock -
trunk/SophyaLib/BaseTools/sophyainit.cc
r3203 r3213 27 27 // Module version number - 2.0 , Jul 2006 28 28 // Module version number - 2.02 , Fev07 Ajout NDataBlock::RenewObjId() 29 // Module version number - 2.1 , Avr07 30 // - Nettoyage machdefs_mkmf.h 31 // - Ajout classe ThSafeOp ---> NDataBlock<T> Sw/SegDataBlock<T> ThreadSafe 32 // 29 33 #define MOD_VERS 2.02 30 34 … … 58 62 ModListP = new map<string, double>; 59 63 60 61 #ifdef xx__mac__62 //InitToolBox();63 //SIOUXSettings.initializeTB = FALSE;64 SIOUXSettings.autocloseonquit = FALSE;65 SIOUXSettings.asktosaveonclose = FALSE;66 SIOUXSettings.showstatusline = TRUE;67 #endif68 64 69 65 // Initialisation des mecanismes PPF I/O … … 206 202 #ifdef __IBMCPP__ 207 203 #ifdef SO_ARCH64 208 compiler = const_cast<char *>("IBM-xlC ") ;204 compiler = const_cast<char *>("IBM-xlC (-q64)") ; 209 205 #else 210 compiler = const_cast<char *>("IBM-xlC (-q64)") ;206 compiler = const_cast<char *>("IBM-xlC") ; 211 207 #endif 212 208 #endif -
trunk/SophyaLib/BaseTools/sversion.h
r3172 r3213 3 3 4 4 #define SOPHYA_VERSION 2.1 5 #define SOPHYA_REVISION 206 #define SOPHYA_TAG "V_ Jan2007"5 #define SOPHYA_REVISION 30 6 #define SOPHYA_TAG "V_Avr2007" 7 7 8 8 #endif -
trunk/SophyaLib/BaseTools/swsegdb.h
r3172 r3213 69 69 SetSize(segsz, swpos.size()); 70 70 SetSwapper(dsw); 71 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 71 72 mSRef->swp = swpos; 72 73 for(size_t k=0; k<mSRef->fgwp.size(); k++) mSRef->fgwp[k] = true; 74 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 73 75 } 74 76 //! Constructor - optional specification of segment size and number of segments … … 82 84 SwSegDataBlock(const SwSegDataBlock<T>& a) 83 85 { 86 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 84 87 mSRef = a.mSRef; 85 88 mSRef->nref++; 89 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 86 90 } 87 91 88 92 //! Destructor. The memory is freed when the last object referencing the data segment is destroyed 89 virtual ~SwSegDataBlock() { Delete(); } 93 virtual ~SwSegDataBlock() 94 { 95 Delete(); 96 } 90 97 //! Adds one segment to the data structure - returns the pointer to the allocated segment. 91 98 virtual size_t Extend() 92 99 { 100 size_t rs = 0; 101 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 93 102 mSRef->swp.push_back(0); 94 103 mSRef->fgwp.push_back(false); 95 return mSRef->swp.size(); 104 rs = mSRef->swp.size(); 105 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 106 return rs; 96 107 } 97 108 /*! \brief Changes the data segment size and reallocates the memory segments … … 102 113 { 103 114 Delete(); 115 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 104 116 mSRef = new SWSDREF; 105 117 mSRef->nref = 1; … … 114 126 } 115 127 mSRef->swapper = NULL; 128 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 116 129 } 117 130 … … 120 133 { 121 134 if (mSRef == NULL) return; 135 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 122 136 if (mSRef->swapper) delete mSRef->swapper; 123 137 mSRef->swapper = dsw.Clone(); 138 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 124 139 } 125 140 … … 133 148 virtual T* GetSegment(size_t k) 134 149 { 150 T* rs = NULL; 151 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 135 152 getSeg(k); 136 153 mSRef->fgcstbuff = false; 137 return mSRef->buff; 154 rs = mSRef->buff; 155 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 156 return rs; 138 157 } 139 158 //! Return the const (read-only) pointer to data segment \b k 140 159 virtual T const * GetCstSegment(size_t k) const 141 160 { 161 T const * rs = NULL; 162 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 142 163 if (getSeg(k)) mSRef->fgcstbuff = true; 143 return mSRef->buff; 164 rs = mSRef->buff; 165 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 166 return rs; 144 167 } 145 168 … … 148 171 { 149 172 Delete(); 173 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 150 174 mSRef = a.mSRef; 151 175 mSRef->nref++; 176 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 152 177 return *this; 153 178 } … … 156 181 void SwapOutBuffer() const 157 182 { 183 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 158 184 if ((mSRef->bidx >= 0) && !mSRef->fgcstbuff) { 159 185 int_8 nswp = mSRef->swapper->WriteToSwap(mSRef->buff, mSRef->segsize, mSRef->bidx, … … 164 190 mSRef->fgcstbuff = true; 165 191 } 192 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 166 193 } 167 194 //! Return the position tag (swap position) table, after call to SwapOutBuffer() … … 180 207 { 181 208 if (mSRef == NULL) return; 209 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 182 210 mSRef->nref--; 183 if (mSRef->nref > 0) { mSRef = NULL; return; } 211 if (mSRef->nref > 0) { 212 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 213 mSRef = NULL; 214 return; 215 } 184 216 if (mSRef->swapper) delete mSRef->swapper; 185 217 delete[] mSRef->buff; 218 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 186 219 delete mSRef; 187 220 mSRef = NULL; … … 214 247 mutable bool fgcstbuff; // true : this is a constant T * buff< 215 248 DataSwapperInterface<T> * swapper; // Data swapper 249 ThSafeOp gThsop; // Mutex for thread safe operation one / SWSDREF struct 216 250 } SWSDREF; 217 251 //! \endcond 218 SWSDREF * mSRef; // SWSDREF structure for reference sharing 252 SWSDREF * mSRef; //!< SWSDREF structure for reference sharing 253 219 254 }; 220 255
Note:
See TracChangeset
for help on using the changeset viewer.