Changeset 3213 in Sophya for trunk/SophyaLib/BaseTools/swsegdb.h


Ignore:
Timestamp:
Apr 11, 2007, 6:12:56 PM (18 years ago)
Author:
ansari
Message:

Sw/SegDataBlock<T> rendu en principe ThreadSafe + changement numero de version SOPHYA et module BaseTools, Reza 11/04/2007

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/swsegdb.h

    r3172 r3213  
    6969    SetSize(segsz, swpos.size());
    7070    SetSwapper(dsw);
     71    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation
    7172    mSRef->swp = swpos;
    7273    for(size_t k=0; k<mSRef->fgwp.size(); k++)  mSRef->fgwp[k] = true;
     74    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
    7375    }
    7476  //! Constructor - optional specification of segment size and number of segments
     
    8284  SwSegDataBlock(const SwSegDataBlock<T>& a)
    8385  {
     86    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation
    8487    mSRef = a.mSRef;
    8588    mSRef->nref++;
     89    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
    8690  }
    8791
    8892  //! 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  }
    9097  //! Adds one segment to the data structure - returns the pointer to the allocated segment.
    9198  virtual size_t Extend()
    9299  {
     100    size_t rs = 0;
     101    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation
    93102    mSRef->swp.push_back(0);
    94103    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;
    96107  }
    97108  /*! \brief Changes the data segment size and reallocates the memory segments
     
    102113  {
    103114    Delete();
     115    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation
    104116    mSRef = new SWSDREF;
    105117    mSRef->nref = 1;
     
    114126    }
    115127    mSRef->swapper = NULL;
     128    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
    116129  }
    117130
     
    120133  {
    121134    if (mSRef == NULL) return;
     135    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation
    122136    if (mSRef->swapper) delete mSRef->swapper; 
    123137    mSRef->swapper = dsw.Clone();
     138    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
    124139  }
    125140
     
    133148  virtual T* GetSegment(size_t k)
    134149  {
     150    T* rs = NULL;
     151    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation
    135152    getSeg(k);
    136153    mSRef->fgcstbuff = false;
    137     return mSRef->buff;
     154    rs = mSRef->buff;
     155    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
     156    return rs;
    138157  }
    139158  //! Return the const (read-only) pointer to data segment \b k         
    140159  virtual T const * GetCstSegment(size_t k) const
    141160  {
     161    T const * rs = NULL;
     162    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation
    142163    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;   
    144167  }
    145168
     
    148171  {
    149172    Delete();
     173    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation
    150174    mSRef = a.mSRef;
    151175    mSRef->nref++;
     176    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
    152177    return *this;
    153178  }
     
    156181  void SwapOutBuffer() const
    157182  {
     183    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation
    158184    if ((mSRef->bidx >= 0) && !mSRef->fgcstbuff) {
    159185      int_8 nswp = mSRef->swapper->WriteToSwap(mSRef->buff, mSRef->segsize, mSRef->bidx,
     
    164190      mSRef->fgcstbuff = true; 
    165191   }
     192    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
    166193  }
    167194  //! Return the position tag (swap position) table, after call to SwapOutBuffer()
     
    180207  {
    181208    if (mSRef == NULL) return;
     209    mSRef->gThsop.lock();   //  (ThreadSafe) - Start of atomic operation
    182210    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    }
    184216    if (mSRef->swapper) delete mSRef->swapper; 
    185217    delete[] mSRef->buff;
     218    mSRef->gThsop.unlock();   //  (ThreadSafe) - End of atomic operation
    186219    delete mSRef;
    187220    mSRef = NULL; 
     
    214247    mutable bool fgcstbuff;            // true : this is a constant T * buff<
    215248    DataSwapperInterface<T> * swapper;   // Data swapper
     249    ThSafeOp gThsop;         // Mutex for thread safe operation one / SWSDREF struct
    216250  } SWSDREF;
    217251  //! \endcond
    218   SWSDREF *  mSRef;    // SWSDREF structure for reference sharing
     252  SWSDREF *  mSRef;    //!< SWSDREF structure for reference sharing
     253
    219254};
    220255
Note: See TracChangeset for help on using the changeset viewer.