Changeset 13041 for OpenSceneGraph/trunk/src/osg/OperationThread.cpp
- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osg/OperationThread.cpp (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osg/OperationThread.cpp
r12292 r13041 56 56 } 57 57 58 bool OperationQueue::empty() 59 { 58 bool OperationQueue::empty() 59 { 60 60 61 61 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_operationsMutex); 62 return _operations.empty(); 62 return _operations.empty(); 63 63 } 64 64 … … 66 66 { 67 67 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_operationsMutex); 68 return static_cast<unsigned int>(_operations.size()); 68 return static_cast<unsigned int>(_operations.size()); 69 69 } 70 70 … … 77 77 78 78 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_operationsMutex); 79 79 80 80 if (_operations.empty()) return osg::ref_ptr<Operation>(); 81 81 82 82 if (_currentOperationIterator == _operations.end()) 83 83 { … … 85 85 _currentOperationIterator = _operations.begin(); 86 86 } 87 87 88 88 ref_ptr<Operation> currentOperation = *_currentOperationIterator; 89 89 … … 140 140 { 141 141 bool needToResetCurrentIterator = (_currentOperationIterator == itr); 142 142 143 143 itr = _operations.erase(itr); 144 144 145 145 if (needToResetCurrentIterator) _currentOperationIterator = itr; 146 146 147 147 } 148 148 else ++itr; … … 153 153 { 154 154 OSG_INFO<<"Doing remove named operation"<<std::endl; 155 155 156 156 // acquire the lock on the operations queue to prevent anyone else for modifying it at the same time 157 157 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_operationsMutex); … … 161 161 itr!=_operations.end();) 162 162 { 163 if ((*itr)->getName()==name) 163 if ((*itr)->getName()==name) 164 164 { 165 165 bool needToResetCurrentIterator = (_currentOperationIterator == itr); 166 166 167 167 itr = _operations.erase(itr); 168 168 169 169 if (needToResetCurrentIterator) _currentOperationIterator = itr; 170 170 } … … 183 183 184 184 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_operationsMutex); 185 185 186 186 _operations.clear(); 187 187 188 188 // reset current operator. 189 189 _currentOperationIterator = _operations.begin(); … … 201 201 // reset current operation iterator to beginning if at end. 202 202 if (_currentOperationIterator==_operations.end()) _currentOperationIterator = _operations.begin(); 203 203 204 204 for(; 205 205 _currentOperationIterator != _operations.end(); … … 216 216 ++_currentOperationIterator; 217 217 } 218 218 219 219 // OSG_INFO<<"Doing op "<<_currentOperation->getName()<<" "<<this<<std::endl; 220 220 … … 233 233 _operationsBlock->release(); 234 234 } 235 235 236 236 void OperationQueue::releaseAllOperations() 237 237 { 238 238 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_operationsMutex); 239 239 240 240 for(Operations::iterator itr = _operations.begin(); 241 241 itr!=_operations.end(); … … 301 301 { 302 302 OSG_INFO<<"set done "<<this<<std::endl; 303 303 304 304 { 305 305 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_threadMutex); … … 322 322 if( isRunning() ) 323 323 { 324 324 325 325 _done = true; 326 326 … … 330 330 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_threadMutex); 331 331 332 if (_operationQueue.valid()) 332 if (_operationQueue.valid()) 333 333 { 334 334 _operationQueue->releaseOperationsBlock(); … … 338 338 if (_currentOperation.valid()) _currentOperation->release(); 339 339 } 340 340 341 341 // then wait for the the thread to stop running. 342 342 while(isRunning()) … … 347 347 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_threadMutex); 348 348 349 if (_operationQueue.valid()) 349 if (_operationQueue.valid()) 350 350 { 351 351 _operationQueue->releaseOperationsBlock(); … … 404 404 ref_ptr<Operation> operation; 405 405 ref_ptr<OperationQueue> operationQueue; 406 406 407 407 { 408 408 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_threadMutex); … … 426 426 (*operation)(_parent.get()); 427 427 428 { 428 { 429 429 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_threadMutex); 430 430 _currentOperation = 0; … … 434 434 if (firstTime) 435 435 { 436 // do a yield to get round a peculiar thread hang when testCancel() is called 436 // do a yield to get round a peculiar thread hang when testCancel() is called 437 437 // in certain circumstances - of which there is no particular pattern. 438 438 YieldCurrentThread(); 439 439 firstTime = false; 440 440 } 441 441 442 442 // OSG_NOTICE<<"operations.size()="<<_operations.size()<<" done="<<_done<<" testCancel()"<<testCancel()<<std::endl; 443 443
