Changeset 3208 in Sophya for trunk/SophyaLib/BaseTools/ndatablock.cc
- Timestamp:
- Apr 10, 2007, 5:57:02 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/ndatablock.cc
r3113 r3208 32 32 template <class T> size_t NDataBlock<T>::NallocData = 0; 33 33 template <class T> size_t NDataBlock<T>::NallocSRef = 0; 34 template <class T> ThSafeOp* NDataBlock<T>::gThsop = NULL; 34 35 35 36 //! Set debug (and level print) for allocation and references debug. … … 88 89 if(Debug_NDataBlock>1) 89 90 cout<<"?_NDataBlock::NDataBlock("<<this<<",n="<<n<<")"<<endl; 91 if (gThsop == NULL) gThsop = new ThSafeOp; 90 92 91 93 Alloc(n, NULL, NULL, fzero); // allocation et mise a zero … … 107 109 cout<<"?_NDataBlock::NDataBlock("<<this 108 110 <<",data="<<data<<",br="<<br<<")"<<endl; 111 if (gThsop == NULL) gThsop = new ThSafeOp; 109 112 110 113 Alloc(n,data,br); … … 119 122 if(Debug_NDataBlock>1) 120 123 cout<<"?_NDataBlock::NDataBlock("<<this<<") default"<<endl; 124 if (gThsop == NULL) gThsop = new ThSafeOp; 121 125 } 122 126 … … 160 164 cout<<"?_NDataBlock::~NDataBlock("<<this<<")"<<endl; 161 165 162 De lete();166 Dealloc(); // ThreadSafe version of Delete() 163 167 } 164 168 … … 197 201 if(&a==NULL) throw(NullPtrError("NDataBlock::Share &a==NULL\n")); 198 202 if(!a.mSRef || a.mSz==0) throw(NullPtrError("NDataBlock::Share a.mSz=0\n")); 203 //--- Start of atomic (in one block) operation for thread safety 204 gThsop->lock(); // (ThreadSafe) 199 205 if(mSRef) Delete(); 200 206 mSz = a.mSz; mSRef = a.mSRef; mSRef->nref++; 207 gThsop->unlock(); // (ThreadSafe) 208 //--- End of atomic operation 201 209 202 210 if(Debug_NDataBlock>1) … … 330 338 throw(NullPtrError("NDataBlock::Alloc br!=NULL && data==NULL\n")); 331 339 if(n==0) throw(SzMismatchError("NDataBlock::Alloc n==0\n")); 340 //--- Start of atomic (in one block) operation for thread safety (ThreadSafe) 341 gThsop->lock(); // (ThreadSafe) 332 342 if(mSRef) Delete(); 333 343 mSz = n; … … 338 348 else {mSRef->data = new T[n]; if (zero) memset(mSRef->data,0,n*sizeof(T));} 339 349 mSRef->bridge = br; 350 gThsop->unlock(); // (ThreadSafe) 351 //--- End of atomic operation (ThreadSafe) 340 352 341 353 if(Debug_NDataBlock>0) { … … 354 366 } 355 367 356 //! Management of de-allocation 368 //! Management of de-allocation (NOT thread-safe) 357 369 template <class T> 358 370 void NDataBlock<T>::Delete(void) … … 460 472 } 461 473 474 /*! 475 \brief Calls the protected Delete() method to set the size to zero 476 This is the public - thread safe version - of the Delete() method 477 The memory is freed if last referenced structure. 478 */ 479 template <class T> 480 void NDataBlock<T>::Dealloc() 481 { 482 gThsop->lock(); 483 Delete(); 484 gThsop->unlock(); 485 } 486 462 487 //////////////// 463 488 // Impression //
Note:
See TracChangeset
for help on using the changeset viewer.