Ignore:
Timestamp:
Apr 10, 2007, 5:57:02 PM (18 years ago)
Author:
ansari
Message:

Ajout classe ThSafeOp (thsafeop.h) pour rendre NDataBlock<T> (et SegDataBlock) thread-safe, ajout methode DataTypeInfo::getTypeId() , implementation ThSafeOp ds ndatablock.cc (.h), Reza 10/04/2007

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/ndatablock.cc

    r3113 r3208  
    3232template <class T> size_t NDataBlock<T>::NallocData       = 0;
    3333template <class T> size_t NDataBlock<T>::NallocSRef       = 0;
     34template <class T> ThSafeOp* NDataBlock<T>::gThsop        = NULL;
    3435
    3536//! Set debug (and level print) for allocation and references debug.
     
    8889if(Debug_NDataBlock>1)
    8990  cout<<"?_NDataBlock::NDataBlock("<<this<<",n="<<n<<")"<<endl;
     91if (gThsop == NULL) gThsop = new ThSafeOp;
    9092
    9193Alloc(n, NULL, NULL, fzero);   // allocation et mise a zero
     
    107109  cout<<"?_NDataBlock::NDataBlock("<<this
    108110      <<",data="<<data<<",br="<<br<<")"<<endl;
     111if (gThsop == NULL) gThsop = new ThSafeOp;
    109112
    110113Alloc(n,data,br);
     
    119122if(Debug_NDataBlock>1)
    120123  cout<<"?_NDataBlock::NDataBlock("<<this<<") default"<<endl;
     124if (gThsop == NULL) gThsop = new ThSafeOp;
    121125}
    122126
     
    160164  cout<<"?_NDataBlock::~NDataBlock("<<this<<")"<<endl;
    161165
    162 Delete();
     166Dealloc();  // ThreadSafe version of Delete()
    163167}
    164168
     
    197201if(&a==NULL) throw(NullPtrError("NDataBlock::Share  &a==NULL\n"));
    198202if(!a.mSRef || a.mSz==0) throw(NullPtrError("NDataBlock::Share a.mSz=0\n"));
     203//--- Start of atomic (in one block) operation for thread safety
     204gThsop->lock();   //  (ThreadSafe)
    199205if(mSRef) Delete();
    200206mSz = a.mSz; mSRef = a.mSRef; mSRef->nref++;
     207gThsop->unlock();   //  (ThreadSafe)
     208//--- End of atomic operation
    201209
    202210if(Debug_NDataBlock>1)
     
    330338  throw(NullPtrError("NDataBlock::Alloc br!=NULL && data==NULL\n"));
    331339if(n==0) throw(SzMismatchError("NDataBlock::Alloc n==0\n"));
     340//--- Start of atomic (in one block) operation for thread safety (ThreadSafe)
     341gThsop->lock();   //  (ThreadSafe)
    332342if(mSRef) Delete();
    333343mSz = n;
     
    338348else {mSRef->data = new T[n]; if (zero) memset(mSRef->data,0,n*sizeof(T));}
    339349mSRef->bridge = br;
     350gThsop->unlock();   //  (ThreadSafe)
     351//--- End of atomic operation (ThreadSafe)
    340352
    341353if(Debug_NDataBlock>0) {
     
    354366}
    355367
    356 //! Management of de-allocation
     368//! Management of de-allocation (NOT thread-safe)
    357369template <class T>
    358370void NDataBlock<T>::Delete(void)
     
    460472}
    461473
     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*/
     479template <class T>
     480void NDataBlock<T>::Dealloc()
     481{
     482  gThsop->lock();
     483  Delete();
     484  gThsop->unlock();
     485}
     486
    462487////////////////
    463488// Impression //
Note: See TracChangeset for help on using the changeset viewer.