Changeset 3214 in Sophya for trunk/SophyaLib/BaseTools/swsegdb.h
- Timestamp:
- Apr 12, 2007, 12:19:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/swsegdb.h
r3213 r3214 84 84 SwSegDataBlock(const SwSegDataBlock<T>& a) 85 85 { 86 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation86 a.mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 87 87 mSRef = a.mSRef; 88 88 mSRef->nref++; 89 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 89 size_t segsz = mSRef->segsize; 90 a.mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 91 buff = new T[segsz]; 92 bidx = -1; 93 fgcstbuff = true; 90 94 } 91 95 … … 113 117 { 114 118 Delete(); 115 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation116 119 mSRef = new SWSDREF; 120 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 117 121 mSRef->nref = 1; 118 122 mSRef->segsize = segsz; 119 123 mSRef->dsid = AnyDataObj::getUniqueId(); 120 mSRef->buff = new T[segsz];121 mSRef->bidx = -1;122 mSRef->fgcstbuff = true;123 124 for(size_t k=0; k<nbseg; k++) { 124 125 mSRef->swp.push_back(0); … … 127 128 mSRef->swapper = NULL; 128 129 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 130 buff = new T[segsz]; 131 bidx = -1; 132 fgcstbuff = true; 129 133 } 130 134 … … 148 152 virtual T* GetSegment(size_t k) 149 153 { 150 T* rs = NULL;151 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation152 154 getSeg(k); 153 mSRef->fgcstbuff = false; 154 rs = mSRef->buff; 155 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 156 return rs; 155 fgcstbuff = false; 156 return buff; 157 157 } 158 158 //! Return the const (read-only) pointer to data segment \b k 159 159 virtual T const * GetCstSegment(size_t k) const 160 160 { 161 T const * rs = NULL; 162 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 163 if (getSeg(k)) mSRef->fgcstbuff = true; 164 rs = mSRef->buff; 165 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 166 return rs; 161 if (getSeg(k)) fgcstbuff = true; 162 return buff; 167 163 } 168 164 … … 171 167 { 172 168 Delete(); 173 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation169 a.mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 174 170 mSRef = a.mSRef; 175 171 mSRef->nref++; 176 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 172 size_t segsz = mSRef->segsize; 173 a.mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 174 buff = new T[segsz]; 175 bidx = -1; 176 fgcstbuff = true; 177 177 return *this; 178 178 } … … 182 182 { 183 183 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 184 if (( mSRef->bidx >= 0) && !mSRef->fgcstbuff) {185 int_8 nswp = mSRef->swapper->WriteToSwap( mSRef->buff, mSRef->segsize, mSRef->bidx,186 mSRef->swp[ mSRef->bidx], mSRef->fgwp[mSRef->bidx]);187 mSRef->swp[ mSRef->bidx] = nswp;188 mSRef->fgwp[ mSRef->bidx] = true;189 mSRef->bidx = -1;190 mSRef->fgcstbuff = true;184 if ((bidx >= 0) && !fgcstbuff) { 185 int_8 nswp = mSRef->swapper->WriteToSwap(buff, mSRef->segsize, bidx, 186 mSRef->swp[bidx], mSRef->fgwp[bidx]); 187 mSRef->swp[bidx] = nswp; 188 mSRef->fgwp[bidx] = true; 189 bidx = -1; 190 fgcstbuff = true; 191 191 } 192 192 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation … … 211 211 if (mSRef->nref > 0) { 212 212 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 213 delete[] buff; 213 214 mSRef = NULL; 214 215 return; 215 216 } 216 217 if (mSRef->swapper) delete mSRef->swapper; 217 delete[] mSRef->buff;218 218 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 219 219 delete mSRef; 220 delete[] buff; 220 221 mSRef = NULL; 221 222 } 222 223 bool getSeg(size_t k) const 223 224 { 224 if (k == mSRef->bidx) return false; 225 if ((mSRef->bidx >= 0) && !mSRef->fgcstbuff) { 226 int_8 nswp = mSRef->swapper->WriteToSwap(mSRef->buff, mSRef->segsize, mSRef->bidx, 227 mSRef->swp[mSRef->bidx], mSRef->fgwp[mSRef->bidx]); 228 mSRef->swp[mSRef->bidx] = nswp; 229 mSRef->fgwp[mSRef->bidx] = true; 225 if (k == bidx) return false; 226 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 227 if ((bidx >= 0) && !fgcstbuff) { 228 int_8 nswp = mSRef->swapper->WriteToSwap(buff, mSRef->segsize, bidx, 229 mSRef->swp[bidx], mSRef->fgwp[bidx]); 230 mSRef->swp[bidx] = nswp; 231 mSRef->fgwp[bidx] = true; 230 232 } 231 233 if (mSRef->fgwp[k]) 232 mSRef->swapper->ReadFromSwap(k, mSRef->swp[k], mSRef->buff, mSRef->segsize);234 mSRef->swapper->ReadFromSwap(k, mSRef->swp[k], buff, mSRef->segsize); 233 235 //DEL-02022007 else { delete[] mSRef->buff; mSRef->buff = new T[mSRef->segsize]; } 234 mSRef->bidx = k; 236 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 237 bidx = k; 235 238 return true; 236 239 } … … 243 246 mutable std::vector< int_8 > swp; // swap position tag for each segment 244 247 mutable std::vector< bool > fgwp; // swap flag (true = already swapped) for each segment 245 mutable T * buff; // Data buffer246 mutable int_8 bidx; // segment index (number) corresponding to buffer247 mutable bool fgcstbuff; // true : this is a constant T * buff<248 248 DataSwapperInterface<T> * swapper; // Data swapper 249 249 ThSafeOp gThsop; // Mutex for thread safe operation one / SWSDREF struct … … 251 251 //! \endcond 252 252 SWSDREF * mSRef; //!< SWSDREF structure for reference sharing 253 mutable T * buff; // Data buffer 254 mutable int_8 bidx; // segment index (number) corresponding to buffer 255 mutable bool fgcstbuff; // true : this is a constant T * buff 253 256 254 257 };
Note:
See TracChangeset
for help on using the changeset viewer.