Changeset 3213 in Sophya for trunk/SophyaLib/BaseTools/swsegdb.h
- Timestamp:
- Apr 11, 2007, 6:12:56 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/swsegdb.h
r3172 r3213 69 69 SetSize(segsz, swpos.size()); 70 70 SetSwapper(dsw); 71 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 71 72 mSRef->swp = swpos; 72 73 for(size_t k=0; k<mSRef->fgwp.size(); k++) mSRef->fgwp[k] = true; 74 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 73 75 } 74 76 //! Constructor - optional specification of segment size and number of segments … … 82 84 SwSegDataBlock(const SwSegDataBlock<T>& a) 83 85 { 86 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 84 87 mSRef = a.mSRef; 85 88 mSRef->nref++; 89 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 86 90 } 87 91 88 92 //! 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 } 90 97 //! Adds one segment to the data structure - returns the pointer to the allocated segment. 91 98 virtual size_t Extend() 92 99 { 100 size_t rs = 0; 101 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 93 102 mSRef->swp.push_back(0); 94 103 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; 96 107 } 97 108 /*! \brief Changes the data segment size and reallocates the memory segments … … 102 113 { 103 114 Delete(); 115 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 104 116 mSRef = new SWSDREF; 105 117 mSRef->nref = 1; … … 114 126 } 115 127 mSRef->swapper = NULL; 128 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 116 129 } 117 130 … … 120 133 { 121 134 if (mSRef == NULL) return; 135 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 122 136 if (mSRef->swapper) delete mSRef->swapper; 123 137 mSRef->swapper = dsw.Clone(); 138 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 124 139 } 125 140 … … 133 148 virtual T* GetSegment(size_t k) 134 149 { 150 T* rs = NULL; 151 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 135 152 getSeg(k); 136 153 mSRef->fgcstbuff = false; 137 return mSRef->buff; 154 rs = mSRef->buff; 155 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 156 return rs; 138 157 } 139 158 //! Return the const (read-only) pointer to data segment \b k 140 159 virtual T const * GetCstSegment(size_t k) const 141 160 { 161 T const * rs = NULL; 162 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 142 163 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; 144 167 } 145 168 … … 148 171 { 149 172 Delete(); 173 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 150 174 mSRef = a.mSRef; 151 175 mSRef->nref++; 176 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 152 177 return *this; 153 178 } … … 156 181 void SwapOutBuffer() const 157 182 { 183 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 158 184 if ((mSRef->bidx >= 0) && !mSRef->fgcstbuff) { 159 185 int_8 nswp = mSRef->swapper->WriteToSwap(mSRef->buff, mSRef->segsize, mSRef->bidx, … … 164 190 mSRef->fgcstbuff = true; 165 191 } 192 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 166 193 } 167 194 //! Return the position tag (swap position) table, after call to SwapOutBuffer() … … 180 207 { 181 208 if (mSRef == NULL) return; 209 mSRef->gThsop.lock(); // (ThreadSafe) - Start of atomic operation 182 210 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 } 184 216 if (mSRef->swapper) delete mSRef->swapper; 185 217 delete[] mSRef->buff; 218 mSRef->gThsop.unlock(); // (ThreadSafe) - End of atomic operation 186 219 delete mSRef; 187 220 mSRef = NULL; … … 214 247 mutable bool fgcstbuff; // true : this is a constant T * buff< 215 248 DataSwapperInterface<T> * swapper; // Data swapper 249 ThSafeOp gThsop; // Mutex for thread safe operation one / SWSDREF struct 216 250 } SWSDREF; 217 251 //! \endcond 218 SWSDREF * mSRef; // SWSDREF structure for reference sharing 252 SWSDREF * mSRef; //!< SWSDREF structure for reference sharing 253 219 254 }; 220 255
Note:
See TracChangeset
for help on using the changeset viewer.