Changeset 3214 in Sophya for trunk/SophyaLib/BaseTools/segdatablock.h
- Timestamp:
- Apr 12, 2007, 12:19:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/segdatablock.h
r3213 r3214 69 69 { 70 70 mSRef = NULL; 71 if (gThsop == NULL) gThsop = new ThSafeOp;72 71 SetSize(segsz, nbseg); 73 72 } … … 75 74 SegDataBlock(const SegDataBlock<T>& a) 76 75 { 77 gThsop->lock(); // (ThreadSafe) - Start of atomic operation76 a.mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 78 77 mSRef = a.mSRef; 79 78 mSRef->nref++; 80 gThsop->unlock(); // (ThreadSafe) - End of atomic operation79 a.mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 81 80 } 82 81 //! copy constructor with specification of flags for data sharing and element value copy … … 84 83 { 85 84 if (share) { 86 gThsop->lock(); // (ThreadSafe) - Start of atomic operation85 a.mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 87 86 mSRef = a.mSRef; 88 87 mSRef->nref++; 89 gThsop->unlock(); // (ThreadSafe) - End of atomic operation88 a.mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 90 89 } 91 90 else { … … 97 96 SegDataBlock(const SegDBInterface<T>& a) 98 97 { 99 if (gThsop == NULL) gThsop = new ThSafeOp;100 98 SegDataBlock<T> * sdb = dynamic_cast< SegDataBlock<T> *>(&a); 101 99 if (sdb != NULL) { 102 gThsop->lock(); // (ThreadSafe) - Start of atomic operation100 sdb->mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 103 101 mSRef = sdb->mSRef; 104 102 mSRef->nref++; 105 gThsop->unlock(); // (ThreadSafe) - End of atomic operation103 sdb->mSRefg->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 106 104 } 107 105 else Clone(a, true); … … 111 109 { 112 110 //DEL cout << " DEBUG-~SegDataBlock() " << hex << mSRef << dec << " NRef()= " << NRef() << endl; 113 gThsop->lock(); // (ThreadSafe) - Start of atomic operation114 111 Delete(); 115 gThsop->unlock(); // (ThreadSafe) - End of atomic operation116 112 } 117 113 … … 121 117 { 122 118 T * p = new T[mSRef->segsize]; 123 gThsop->lock(); // (ThreadSafe) - Start of atomic operation119 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 124 120 mSRef->dseg.push_back(p); 125 gThsop->unlock(); // (ThreadSafe) - End of atomic operation 126 return( mSRef->dseg.size()); 121 size_t rs = mSRef->dseg.size(); 122 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 123 return( rs ); 127 124 } 128 125 … … 131 128 virtual void SetSize(size_t segsz, size_t nbseg=0) 132 129 { 133 gThsop->lock(); // (ThreadSafe) - Start of atomic operation134 130 Delete(); 135 131 mSRef = new SDREF; 132 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 136 133 mSRef->nref = 1; 137 134 mSRef->segsize = segsz; 138 135 mSRef->dsid = AnyDataObj::getUniqueId(); 139 136 for(size_t k=0; k<nbseg; k++) Extend_P(); 140 gThsop->unlock(); // (ThreadSafe) - End of atomic operation137 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 141 138 } 142 139 //! Shares the data between two SegDataBlock objects 143 140 void Share(const SegDataBlock<T>& a) 144 141 { 145 gThsop->lock(); // (ThreadSafe) - Start of atomic operation146 142 Delete(); 143 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 147 144 mSRef = a.mSRef; 148 145 mSRef->nref++; 149 gThsop->unlock(); // (ThreadSafe) - End of atomic operation146 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 150 147 } 151 148 … … 153 150 void Clone(const SegDBInterface<T> & a, bool cpval=true) 154 151 { 155 gThsop->lock(); // (ThreadSafe) - Start of atomic operation156 152 Delete(); 157 153 mSRef = new SDREF; 154 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 158 155 mSRef->nref = 1; 159 156 mSRef->segsize = a.SegmentSize(); 160 gThsop->unlock(); // (ThreadSafe) - End of atomic operation157 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 161 158 for(size_t k=0; k<a.NbSegments(); k++) { 162 159 Extend(); … … 254 251 { 255 252 if (mSRef == NULL) return; 253 mSRef->gThsop.lock(); 256 254 mSRef->nref--; 257 if (mSRef->nref > 0) { mSRef = NULL; return; } 255 if (mSRef->nref > 0) { 256 mSRef->gThsop.unlock(); 257 mSRef = NULL; 258 return; 259 } 258 260 //DEL cout << " DEBUG-SegDataBlock::Delete() NbSegments() = " << NbSegments() << endl; 259 261 for(size_t k=0; k<NbSegments(); k++) { … … 261 263 mSRef->dseg[k] = NULL; 262 264 } 265 mSRef->gThsop.unlock(); 263 266 delete mSRef; 264 267 mSRef = NULL; … … 280 283 std::vector<T *> dseg; 281 284 size_t segsize; 285 ThSafeOp gThsop; // Mutex for thread safe operation 282 286 } SDREF; 283 287 /*! \endcond */ 284 288 SDREF * mSRef; //!< SDREF structure for reference sharing 285 289 286 static ThSafeOp* gThsop; //!< Mutex for thread safe operation287 290 }; 288 291 289 template <class T> ThSafeOp* SegDataBlock<T>::gThsop = NULL; // static member initialized to NULL290 292 291 293 //! Definition of operator \<\< for ascii formatted output of SegDataBlock
Note:
See TracChangeset
for help on using the changeset viewer.