diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 401e7896de..dc9b985969 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -216,7 +216,6 @@ endif(APPLE) target_link_libraries(openmw-cs ${OSG_LIBRARIES} - ${OPENTHREADS_LIBRARIES} ${OSGTEXT_LIBRARIES} ${OSGUTIL_LIBRARIES} ${OSGVIEWER_LIBRARIES} diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 9747c3de05..f3186e76a9 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -1,5 +1,8 @@ #include "scenewidget.hpp" +#include +#include + #include #include #include @@ -184,7 +187,7 @@ void CompositeViewer::update() double minFrameTime = _runMaxFrameRate > 0.0 ? 1.0 / _runMaxFrameRate : 0.0; if (dt < minFrameTime) { - OpenThreads::Thread::microSleep(1000*1000*(minFrameTime-dt)); + std::this_thread::sleep_for(std::chrono::duration(minFrameTime - dt)); } } diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index d174d7b155..fddfa276f9 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -123,7 +123,6 @@ include_directories( target_link_libraries(openmw ${OSG_LIBRARIES} - ${OPENTHREADS_LIBRARIES} ${OSGPARTICLE_LIBRARIES} ${OSGUTIL_LIBRARIES} ${OSGDB_LIBRARIES} diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index b1c5bcfdec..ec12d6a1f7 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include #include @@ -886,7 +888,7 @@ void OMW::Engine::go() if (!frame(dt)) { - OpenThreads::Thread::microSleep(5000); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); continue; } else diff --git a/apps/openmw/mwbase/environment.cpp b/apps/openmw/mwbase/environment.cpp index c70debda1d..764a07ec96 100644 --- a/apps/openmw/mwbase/environment.cpp +++ b/apps/openmw/mwbase/environment.cpp @@ -1,8 +1,8 @@ #include "environment.hpp" #include - -#include +#include +#include #include "world.hpp" #include "scriptmanager.hpp" @@ -99,7 +99,7 @@ void MWBase::Environment::limitFrameRate(double dt) const double minFrameTime = 1.0 / static_cast(mFrameRateLimit); if (thisFrameTime < minFrameTime) { - OpenThreads::Thread::microSleep(1000*1000*(minFrameTime-thisFrameTime)); + std::this_thread::sleep_for(std::chrono::duration(minFrameTime - thisFrameTime)); } } } diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 8f83c165ae..02b42c9cde 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1,6 +1,8 @@ #include "windowmanagerimp.hpp" #include +#include +#include #include @@ -715,7 +717,7 @@ namespace MWGui MWBase::Environment::get().getInputManager()->update(dt, true, false); if (!mWindowVisible) - OpenThreads::Thread::microSleep(5000); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); else { mViewer->eventTraversal(); @@ -1754,7 +1756,7 @@ namespace MWGui if (!mWindowVisible) { mVideoWidget->pause(); - OpenThreads::Thread::microSleep(5000); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); } else { diff --git a/apps/openmw/mwrender/objectpaging.cpp b/apps/openmw/mwrender/objectpaging.cpp index 4810b2385b..fd12ad3677 100644 --- a/apps/openmw/mwrender/objectpaging.cpp +++ b/apps/openmw/mwrender/objectpaging.cpp @@ -428,7 +428,7 @@ namespace MWRender if (activeGrid) { - OpenThreads::ScopedLock lock(mRefTrackerMutex); + std::lock_guard lock(mRefTrackerMutex); for (auto ref : getRefTracker().mBlacklist) refs.erase(ref); } @@ -464,7 +464,7 @@ namespace MWRender float dSqr = (viewPoint - pos).length2(); if (!activeGrid) { - OpenThreads::ScopedLock lock(mSizeCacheMutex); + std::lock_guard lock(mSizeCacheMutex); SizeCache::iterator found = mSizeCache.find(pair.first); if (found != mSizeCache.end() && found->second < dSqr*minSize*minSize) continue; @@ -501,7 +501,7 @@ namespace MWRender } { - OpenThreads::ScopedLock lock(mRefTrackerMutex); + std::lock_guard lock(mRefTrackerMutex); if (getRefTracker().mDisabled.count(pair.first)) continue; } @@ -509,7 +509,7 @@ namespace MWRender float radius2 = cnode->getBound().radius2() * ref.mScale*ref.mScale; if (radius2 < dSqr*minSize*minSize && !activeGrid) { - OpenThreads::ScopedLock lock(mSizeCacheMutex); + std::lock_guard lock(mSizeCacheMutex); mSizeCache[pair.first] = radius2; continue; } @@ -685,7 +685,7 @@ namespace MWRender return false; { - OpenThreads::ScopedLock lock(mRefTrackerMutex); + std::lock_guard lock(mRefTrackerMutex); if (enabled && !getWritableRefTracker().mDisabled.erase(refnum)) return false; if (!enabled && !getWritableRefTracker().mDisabled.insert(refnum).second) return false; if (mRefTrackerLocked) return false; @@ -706,7 +706,7 @@ namespace MWRender return false; { - OpenThreads::ScopedLock lock(mRefTrackerMutex); + std::lock_guard lock(mRefTrackerMutex); if (!getWritableRefTracker().mBlacklist.insert(refnum).second) return false; if (mRefTrackerLocked) return false; } @@ -724,7 +724,7 @@ namespace MWRender void ObjectPaging::clear() { - OpenThreads::ScopedLock lock(mRefTrackerMutex); + std::lock_guard lock(mRefTrackerMutex); mRefTrackerNew.mDisabled.clear(); mRefTrackerNew.mBlacklist.clear(); mRefTrackerLocked = true; @@ -734,7 +734,7 @@ namespace MWRender { if (!mRefTrackerLocked) return false; { - OpenThreads::ScopedLock lock(mRefTrackerMutex); + std::lock_guard lock(mRefTrackerMutex); mRefTrackerLocked = false; if (mRefTracker == mRefTrackerNew) return false; diff --git a/apps/openmw/mwrender/objectpaging.hpp b/apps/openmw/mwrender/objectpaging.hpp index 9c2c54f655..2ca3020386 100644 --- a/apps/openmw/mwrender/objectpaging.hpp +++ b/apps/openmw/mwrender/objectpaging.hpp @@ -5,7 +5,7 @@ #include #include -#include +#include namespace Resource { @@ -58,7 +58,7 @@ namespace MWRender float mMinSizeMergeFactor; float mMinSizeCostMultiplier; - OpenThreads::Mutex mRefTrackerMutex; + std::mutex mRefTrackerMutex; struct RefTracker { std::set mDisabled; @@ -72,7 +72,7 @@ namespace MWRender const RefTracker& getRefTracker() const { return mRefTracker; } RefTracker& getWritableRefTracker() { return mRefTrackerLocked ? mRefTrackerNew : mRefTracker; } - OpenThreads::Mutex mSizeCacheMutex; + std::mutex mSizeCacheMutex; typedef std::map SizeCache; SizeCache mSizeCache; }; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index fc78b6ebbc..0c6e48645b 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include #include #include @@ -709,24 +711,24 @@ namespace MWRender virtual void operator () (osg::RenderInfo& renderInfo) const { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); if (renderInfo.getState()->getFrameStamp()->getFrameNumber() >= mFrame) { mDone = true; - mCondition.signal(); + mCondition.notify_one(); } } void waitTillDone() { - OpenThreads::ScopedLock lock(mMutex); + std::unique_lock lock(mMutex); if (mDone) return; - mCondition.wait(&mMutex); + mCondition.wait(lock); } - mutable OpenThreads::Condition mCondition; - mutable OpenThreads::Mutex mMutex; + mutable std::condition_variable mCondition; + mutable std::mutex mMutex; mutable bool mDone; unsigned int mFrame; }; diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 5955187261..1606b29797 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -4,6 +4,10 @@ #include #include #include +#include +#include +#include +#include #include @@ -11,11 +15,6 @@ #include #include -#include -#include -#include -#include - #include "openal_output.hpp" #include "sound_decoder.hpp" #include "sound.hpp" @@ -309,31 +308,33 @@ const ALfloat OpenAL_SoundStream::sBufferLength = 0.125f; // // A background streaming thread (keeps active streams processed) // -struct OpenAL_Output::StreamThread : public OpenThreads::Thread { +struct OpenAL_Output::StreamThread +{ typedef std::vector StreamVec; StreamVec mStreams; std::atomic mQuitNow; - OpenThreads::Mutex mMutex; - OpenThreads::Condition mCondVar; + std::mutex mMutex; + std::condition_variable mCondVar; + std::thread mThread; StreamThread() : mQuitNow(false) + , mThread([this] { run(); }) { - start(); } ~StreamThread() { mQuitNow = true; mMutex.lock(); mMutex.unlock(); - mCondVar.broadcast(); - join(); + mCondVar.notify_all(); + mThread.join(); } // thread entry point - virtual void run() + void run() { - OpenThreads::ScopedLock lock(mMutex); + std::unique_lock lock(mMutex); while(!mQuitNow) { StreamVec::iterator iter = mStreams.begin(); @@ -345,30 +346,30 @@ struct OpenAL_Output::StreamThread : public OpenThreads::Thread { ++iter; } - mCondVar.wait(&mMutex, 50); + mCondVar.wait_for(lock, std::chrono::milliseconds(50)); } } void add(OpenAL_SoundStream *stream) { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); if(std::find(mStreams.begin(), mStreams.end(), stream) == mStreams.end()) { mStreams.push_back(stream); - mCondVar.broadcast(); + mCondVar.notify_all(); } } void remove(OpenAL_SoundStream *stream) { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); StreamVec::iterator iter = std::find(mStreams.begin(), mStreams.end(), stream); if(iter != mStreams.end()) mStreams.erase(iter); } void removeAll() { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); mStreams.clear(); } @@ -1341,7 +1342,7 @@ double OpenAL_Output::getStreamOffset(Stream *sound) { if(!sound->mHandle) return 0.0; OpenAL_SoundStream *stream = reinterpret_cast(sound->mHandle); - OpenThreads::ScopedLock lock(mStreamThread->mMutex); + std::lock_guard lock(mStreamThread->mMutex); return stream->getStreamOffset(); } @@ -1349,7 +1350,7 @@ float OpenAL_Output::getStreamLoudness(Stream *sound) { if(!sound->mHandle) return 0.0; OpenAL_SoundStream *stream = reinterpret_cast(sound->mHandle); - OpenThreads::ScopedLock lock(mStreamThread->mMutex); + std::lock_guard lock(mStreamThread->mMutex); return stream->getCurrentLoudness(); } @@ -1357,7 +1358,7 @@ bool OpenAL_Output::isStreamPlaying(Stream *sound) { if(!sound->mHandle) return false; OpenAL_SoundStream *stream = reinterpret_cast(sound->mHandle); - OpenThreads::ScopedLock lock(mStreamThread->mMutex); + std::lock_guard lock(mStreamThread->mMutex); return stream->isPlaying(); } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 1138483946..64316789fe 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -1,6 +1,8 @@ #include "scene.hpp" #include +#include +#include #include #include @@ -1140,7 +1142,7 @@ namespace MWWorld } else loadingListener->setProgress(0); - OpenThreads::Thread::microSleep(5000); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); } } diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index fc93706a37..cf27b7128d 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -2,8 +2,6 @@ #include -#include - #include #include @@ -548,7 +546,7 @@ namespace ESMTerrain Terrain::LayerInfo Storage::getLayerInfo(const std::string& texture) { - OpenThreads::ScopedLock lock(mLayerInfoMutex); + std::lock_guard lock(mLayerInfoMutex); // Already have this cached? std::map::iterator found = mLayerInfoMap.find(texture); diff --git a/components/esmterrain/storage.hpp b/components/esmterrain/storage.hpp index a5f62ba48d..c645311401 100644 --- a/components/esmterrain/storage.hpp +++ b/components/esmterrain/storage.hpp @@ -2,8 +2,7 @@ #define COMPONENTS_ESM_TERRAIN_STORAGE_H #include - -#include +#include #include @@ -138,7 +137,7 @@ namespace ESMTerrain std::string getTextureName (UniqueTextureId id); std::map mLayerInfoMap; - OpenThreads::Mutex mLayerInfoMutex; + std::mutex mLayerInfoMutex; std::string mNormalMapPattern; std::string mNormalHeightMapPattern; diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 6830e792fe..8266b5e016 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1,5 +1,7 @@ #include "nifloader.hpp" +#include + #include #include #include @@ -1730,8 +1732,8 @@ namespace NifOsg { typedef std::set, CompareStateAttribute> Cache; static Cache sCache; - static OpenThreads::Mutex sMutex; - OpenThreads::ScopedLock lock(sMutex); + static std::mutex sMutex; + std::lock_guard lock(sMutex); typename Cache::iterator found = sCache.find(attr); if (found == sCache.end()) found = sCache.insert(attr).first; diff --git a/components/resource/multiobjectcache.cpp b/components/resource/multiobjectcache.cpp index d6639d3aec..9d75d2480a 100644 --- a/components/resource/multiobjectcache.cpp +++ b/components/resource/multiobjectcache.cpp @@ -21,7 +21,7 @@ namespace Resource { std::vector > objectsToRemove; { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); // Remove unreferenced entries from object cache ObjectCacheMap::iterator oitr = _objectCache.begin(); @@ -45,7 +45,7 @@ namespace Resource void MultiObjectCache::clear() { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); _objectCache.clear(); } @@ -56,13 +56,13 @@ namespace Resource OSG_ALWAYS << " trying to add NULL object to cache for " << filename << std::endl; return; } - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); _objectCache.insert(std::make_pair(filename, object)); } osg::ref_ptr MultiObjectCache::takeFromObjectCache(const std::string &fileName) { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); ObjectCacheMap::iterator found = _objectCache.find(fileName); if (found == _objectCache.end()) return osg::ref_ptr(); @@ -76,7 +76,7 @@ namespace Resource void MultiObjectCache::releaseGLObjects(osg::State *state) { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); for(ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); @@ -89,7 +89,7 @@ namespace Resource unsigned int MultiObjectCache::getCacheSize() const { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); return _objectCache.size(); } diff --git a/components/resource/multiobjectcache.hpp b/components/resource/multiobjectcache.hpp index b73e29d50f..543406ebd8 100644 --- a/components/resource/multiobjectcache.hpp +++ b/components/resource/multiobjectcache.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -43,7 +44,7 @@ namespace Resource typedef std::multimap > ObjectCacheMap; ObjectCacheMap _objectCache; - mutable OpenThreads::Mutex _objectCacheMutex; + mutable std::mutex _objectCacheMutex; }; diff --git a/components/resource/objectcache.hpp b/components/resource/objectcache.hpp index 24d7d04a97..6e309a7f77 100644 --- a/components/resource/objectcache.hpp +++ b/components/resource/objectcache.hpp @@ -26,6 +26,7 @@ #include #include +#include namespace osg { @@ -53,7 +54,7 @@ class GenericObjectCache : public osg::Referenced void updateTimeStampOfObjectsInCacheWithExternalReferences(double referenceTime) { // look for objects with external references and update their time stamp. - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); for(typename ObjectCacheMap::iterator itr=_objectCache.begin(); itr!=_objectCache.end(); ++itr) { // If ref count is greater than 1, the object has an external reference. @@ -71,7 +72,7 @@ class GenericObjectCache : public osg::Referenced { std::vector > objectsToRemove; { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); // Remove expired entries from object cache typename ObjectCacheMap::iterator oitr = _objectCache.begin(); while(oitr != _objectCache.end()) @@ -92,21 +93,21 @@ class GenericObjectCache : public osg::Referenced /** Remove all objects in the cache regardless of having external references or expiry times.*/ void clear() { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); _objectCache.clear(); } /** Add a key,object,timestamp triple to the Registry::ObjectCache.*/ void addEntryToObjectCache(const KeyType& key, osg::Object* object, double timestamp = 0.0) { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); _objectCache[key]=ObjectTimeStampPair(object,timestamp); } /** Remove Object from cache.*/ void removeFromObjectCache(const KeyType& key) { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); typename ObjectCacheMap::iterator itr = _objectCache.find(key); if (itr!=_objectCache.end()) _objectCache.erase(itr); } @@ -114,7 +115,7 @@ class GenericObjectCache : public osg::Referenced /** Get an ref_ptr from the object cache*/ osg::ref_ptr getRefFromObjectCache(const KeyType& key) { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); typename ObjectCacheMap::iterator itr = _objectCache.find(key); if (itr!=_objectCache.end()) return itr->second.first; @@ -124,7 +125,7 @@ class GenericObjectCache : public osg::Referenced /** Check if an object is in the cache, and if it is, update its usage time stamp. */ bool checkInObjectCache(const KeyType& key, double timeStamp) { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); typename ObjectCacheMap::iterator itr = _objectCache.find(key); if (itr!=_objectCache.end()) { @@ -137,7 +138,7 @@ class GenericObjectCache : public osg::Referenced /** call releaseGLObjects on all objects attached to the object cache.*/ void releaseGLObjects(osg::State* state) { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); for(typename ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); ++itr) { osg::Object* object = itr->second.first.get(); @@ -148,7 +149,7 @@ class GenericObjectCache : public osg::Referenced /** call node->accept(nv); for all nodes in the objectCache. */ void accept(osg::NodeVisitor& nv) { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); for(typename ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); ++itr) { osg::Object* object = itr->second.first.get(); @@ -165,7 +166,7 @@ class GenericObjectCache : public osg::Referenced template void call(Functor& f) { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); for (typename ObjectCacheMap::iterator it = _objectCache.begin(); it != _objectCache.end(); ++it) f(it->first, it->second.first.get()); } @@ -173,7 +174,7 @@ class GenericObjectCache : public osg::Referenced /** Get the number of objects in the cache. */ unsigned int getCacheSize() const { - OpenThreads::ScopedLock lock(_objectCacheMutex); + std::lock_guard lock(_objectCacheMutex); return _objectCache.size(); } @@ -185,7 +186,7 @@ class GenericObjectCache : public osg::Referenced typedef std::map ObjectCacheMap; ObjectCacheMap _objectCache; - mutable OpenThreads::Mutex _objectCacheMutex; + mutable std::mutex _objectCacheMutex; }; diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index 8264e3b1ee..ca6c7c895e 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -126,7 +126,7 @@ namespace Resource void clearCache() { - OpenThreads::ScopedLock lock(_listMutex); + std::lock_guard lock(_listMutex); _sharedTextureList.clear(); _sharedStateSetList.clear(); } @@ -625,7 +625,7 @@ namespace Resource mShaderManager->releaseGLObjects(state); - OpenThreads::ScopedLock lock(mSharedStateMutex); + std::lock_guard lock(mSharedStateMutex); mSharedStateManager->releaseGLObjects(state); } @@ -717,7 +717,7 @@ namespace Resource if (mIncrementalCompileOperation) { - OpenThreads::ScopedLock lock(*mIncrementalCompileOperation->getToCompiledMutex()); + std::lock_guard lock(*mIncrementalCompileOperation->getToCompiledMutex()); osgUtil::IncrementalCompileOperation::CompileSets& sets = mIncrementalCompileOperation->getToCompile(); for(osgUtil::IncrementalCompileOperation::CompileSets::iterator it = sets.begin(); it != sets.end();) { @@ -738,7 +738,7 @@ namespace Resource { ResourceManager::clearCache(); - OpenThreads::ScopedLock lock(mSharedStateMutex); + std::lock_guard lock(mSharedStateMutex); mSharedStateManager->clearCache(); mInstanceCache->clear(); } @@ -747,12 +747,12 @@ namespace Resource { if (mIncrementalCompileOperation) { - OpenThreads::ScopedLock lock(*mIncrementalCompileOperation->getToCompiledMutex()); + std::lock_guard lock(*mIncrementalCompileOperation->getToCompiledMutex()); stats->setAttribute(frameNumber, "Compiling", mIncrementalCompileOperation->getToCompile().size()); } { - OpenThreads::ScopedLock lock(mSharedStateMutex); + std::lock_guard lock(mSharedStateMutex); stats->setAttribute(frameNumber, "Texture", mSharedStateManager->getNumSharedTextures()); stats->setAttribute(frameNumber, "StateSet", mSharedStateManager->getNumSharedStateSets()); } diff --git a/components/resource/scenemanager.hpp b/components/resource/scenemanager.hpp index bbe88c9a0e..3a72caf6a3 100644 --- a/components/resource/scenemanager.hpp +++ b/components/resource/scenemanager.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -159,7 +160,7 @@ namespace Resource osg::ref_ptr mInstanceCache; osg::ref_ptr mSharedStateManager; - mutable OpenThreads::Mutex mSharedStateMutex; + mutable std::mutex mSharedStateMutex; Resource::ImageManager* mImageManager; Resource::NifFileManager* mNifFileManager; diff --git a/components/sceneutil/mwshadowtechnique.cpp b/components/sceneutil/mwshadowtechnique.cpp index 98771bbb42..fa38da54e4 100644 --- a/components/sceneutil/mwshadowtechnique.cpp +++ b/components/sceneutil/mwshadowtechnique.cpp @@ -891,7 +891,7 @@ MWShadowTechnique::ViewDependentData* MWShadowTechnique::createViewDependentData MWShadowTechnique::ViewDependentData* MWShadowTechnique::getViewDependentData(osgUtil::CullVisitor* cv) { - OpenThreads::ScopedLock lock(_viewDependentDataMapMutex); + std::lock_guard lock(_viewDependentDataMapMutex); ViewDependentDataMap::iterator itr = _viewDependentDataMap.find(cv); if (itr!=_viewDependentDataMap.end()) return itr->second.get(); @@ -1343,7 +1343,7 @@ void MWShadowTechnique::cull(osgUtil::CullVisitor& cv) std::string validRegionUniformName = "validRegionMatrix" + std::to_string(sm_i); osg::ref_ptr validRegionUniform; - OpenThreads::ScopedLock lock(_accessUniformsAndProgramMutex); + std::lock_guard lock(_accessUniformsAndProgramMutex); for (auto uniform : _uniforms) { @@ -1467,7 +1467,7 @@ void MWShadowTechnique::createShaders() unsigned int _baseTextureUnit = 0; - OpenThreads::ScopedLock lock(_accessUniformsAndProgramMutex); + std::lock_guard lock(_accessUniformsAndProgramMutex); _shadowCastingStateSet = new osg::StateSet; @@ -2980,7 +2980,7 @@ osg::StateSet* MWShadowTechnique::selectStateSetForRenderingShadow(ViewDependent osg::ref_ptr stateset = vdd.getStateSet(); - OpenThreads::ScopedLock lock(_accessUniformsAndProgramMutex); + std::lock_guard lock(_accessUniformsAndProgramMutex); vdd.getStateSet()->clear(); @@ -3057,7 +3057,7 @@ void MWShadowTechnique::resizeGLObjectBuffers(unsigned int /*maxSize*/) void MWShadowTechnique::releaseGLObjects(osg::State* state) const { - OpenThreads::ScopedLock lock(_viewDependentDataMapMutex); + std::lock_guard lock(_viewDependentDataMapMutex); for(ViewDependentDataMap::const_iterator itr = _viewDependentDataMap.begin(); itr != _viewDependentDataMap.end(); ++itr) diff --git a/components/sceneutil/mwshadowtechnique.hpp b/components/sceneutil/mwshadowtechnique.hpp index 85e548b4b3..77d0bd2b26 100644 --- a/components/sceneutil/mwshadowtechnique.hpp +++ b/components/sceneutil/mwshadowtechnique.hpp @@ -19,6 +19,8 @@ #ifndef COMPONENTS_SCENEUTIL_MWSHADOWTECHNIQUE_H #define COMPONENTS_SCENEUTIL_MWSHADOWTECHNIQUE_H 1 +#include + #include #include #include @@ -234,7 +236,7 @@ namespace SceneUtil { virtual ~MWShadowTechnique(); typedef std::map< osgUtil::CullVisitor*, osg::ref_ptr > ViewDependentDataMap; - mutable OpenThreads::Mutex _viewDependentDataMapMutex; + mutable std::mutex _viewDependentDataMapMutex; ViewDependentDataMap _viewDependentDataMap; osg::ref_ptr _shadowRecievingPlaceholderStateSet; @@ -245,7 +247,7 @@ namespace SceneUtil { osg::ref_ptr _fallbackShadowMapTexture; typedef std::vector< osg::ref_ptr > Uniforms; - mutable OpenThreads::Mutex _accessUniformsAndProgramMutex; + mutable std::mutex _accessUniformsAndProgramMutex; Uniforms _uniforms; osg::ref_ptr _program; diff --git a/components/shader/shadermanager.cpp b/components/shader/shadermanager.cpp index 4495e5b2e5..490c9d4383 100644 --- a/components/shader/shadermanager.cpp +++ b/components/shader/shadermanager.cpp @@ -273,7 +273,7 @@ namespace Shader osg::ref_ptr ShaderManager::getShader(const std::string &templateName, const ShaderManager::DefineMap &defines, osg::Shader::Type shaderType) { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); // read the template if we haven't already TemplateMap::iterator templateIt = mShaderTemplates.find(templateName); @@ -323,7 +323,7 @@ namespace Shader osg::ref_ptr ShaderManager::getProgram(osg::ref_ptr vertexShader, osg::ref_ptr fragmentShader) { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); ProgramMap::iterator found = mPrograms.find(std::make_pair(vertexShader, fragmentShader)); if (found == mPrograms.end()) { @@ -362,7 +362,7 @@ namespace Shader void ShaderManager::releaseGLObjects(osg::State *state) { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); for (auto shader : mShaders) { if (shader.second != nullptr) diff --git a/components/shader/shadermanager.hpp b/components/shader/shadermanager.hpp index 8c5d6dfac2..ed5bbc907b 100644 --- a/components/shader/shadermanager.hpp +++ b/components/shader/shadermanager.hpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -10,8 +11,6 @@ #include -#include - namespace Shader { @@ -63,7 +62,7 @@ namespace Shader typedef std::map, osg::ref_ptr >, osg::ref_ptr > ProgramMap; ProgramMap mPrograms; - OpenThreads::Mutex mMutex; + std::mutex mMutex; const osg::ref_ptr mShadowMapAlphaTestEnableUniform = new osg::Uniform(); const osg::ref_ptr mShadowMapAlphaTestDisableUniform = new osg::Uniform(); diff --git a/components/terrain/buffercache.cpp b/components/terrain/buffercache.cpp index 1734686def..5871b96bc0 100644 --- a/components/terrain/buffercache.cpp +++ b/components/terrain/buffercache.cpp @@ -2,8 +2,6 @@ #include -#include - #include #include "defs.hpp" @@ -180,7 +178,7 @@ namespace Terrain osg::ref_ptr BufferCache::getUVBuffer(unsigned int numVerts) { - OpenThreads::ScopedLock lock(mUvBufferMutex); + std::lock_guard lock(mUvBufferMutex); if (mUvBufferMap.find(numVerts) != mUvBufferMap.end()) { return mUvBufferMap[numVerts]; @@ -210,7 +208,7 @@ namespace Terrain osg::ref_ptr BufferCache::getIndexBuffer(unsigned int numVerts, unsigned int flags) { std::pair id = std::make_pair(numVerts, flags); - OpenThreads::ScopedLock lock(mIndexBufferMutex); + std::lock_guard lock(mIndexBufferMutex); if (mIndexBufferMap.find(id) != mIndexBufferMap.end()) { @@ -234,11 +232,11 @@ namespace Terrain void BufferCache::clearCache() { { - OpenThreads::ScopedLock lock(mIndexBufferMutex); + std::lock_guard lock(mIndexBufferMutex); mIndexBufferMap.clear(); } { - OpenThreads::ScopedLock lock(mUvBufferMutex); + std::lock_guard lock(mUvBufferMutex); mUvBufferMap.clear(); } } @@ -246,12 +244,12 @@ namespace Terrain void BufferCache::releaseGLObjects(osg::State *state) { { - OpenThreads::ScopedLock lock(mIndexBufferMutex); + std::lock_guard lock(mIndexBufferMutex); for (auto indexbuffer : mIndexBufferMap) indexbuffer.second->releaseGLObjects(state); } { - OpenThreads::ScopedLock lock(mUvBufferMutex); + std::lock_guard lock(mUvBufferMutex); for (auto uvbuffer : mUvBufferMap) uvbuffer.second->releaseGLObjects(state); } diff --git a/components/terrain/buffercache.hpp b/components/terrain/buffercache.hpp index 37563d2c67..929dbad6ff 100644 --- a/components/terrain/buffercache.hpp +++ b/components/terrain/buffercache.hpp @@ -6,6 +6,7 @@ #include #include +#include namespace Terrain { @@ -30,10 +31,10 @@ namespace Terrain // Index buffers are shared across terrain batches where possible. There is one index buffer for each // combination of LOD deltas and index buffer LOD we may need. std::map, osg::ref_ptr > mIndexBufferMap; - OpenThreads::Mutex mIndexBufferMutex; + std::mutex mIndexBufferMutex; std::map > mUvBufferMap; - OpenThreads::Mutex mUvBufferMutex; + std::mutex mUvBufferMutex; }; } diff --git a/components/terrain/compositemaprenderer.cpp b/components/terrain/compositemaprenderer.cpp index ee4a66fcde..2a3fa47daa 100644 --- a/components/terrain/compositemaprenderer.cpp +++ b/components/terrain/compositemaprenderer.cpp @@ -1,7 +1,5 @@ #include "compositemaprenderer.hpp" -#include - #include #include #include @@ -50,7 +48,7 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const if (mWorkQueue) mUnrefQueue->flush(mWorkQueue.get()); - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); if (mImmediateCompileSet.empty() && mCompileSet.empty()) return; @@ -177,7 +175,7 @@ void CompositeMapRenderer::setTargetFrameRate(float framerate) void CompositeMapRenderer::addCompositeMap(CompositeMap* compositeMap, bool immediate) { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); if (immediate) mImmediateCompileSet.insert(compositeMap); else @@ -186,7 +184,7 @@ void CompositeMapRenderer::addCompositeMap(CompositeMap* compositeMap, bool imme void CompositeMapRenderer::setImmediate(CompositeMap* compositeMap) { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); CompileSet::iterator found = mCompileSet.find(compositeMap); if (found == mCompileSet.end()) return; @@ -199,7 +197,7 @@ void CompositeMapRenderer::setImmediate(CompositeMap* compositeMap) unsigned int CompositeMapRenderer::getCompileSetSize() const { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); return mCompileSet.size(); } diff --git a/components/terrain/compositemaprenderer.hpp b/components/terrain/compositemaprenderer.hpp index 201130e303..9d5719c233 100644 --- a/components/terrain/compositemaprenderer.hpp +++ b/components/terrain/compositemaprenderer.hpp @@ -3,9 +3,8 @@ #include -#include - #include +#include namespace osg { @@ -76,7 +75,7 @@ namespace Terrain mutable CompileSet mCompileSet; mutable CompileSet mImmediateCompileSet; - mutable OpenThreads::Mutex mMutex; + mutable std::mutex mMutex; osg::ref_ptr mFBO; }; diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index e094330610..ca1dcb08ce 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -453,7 +453,7 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv) void QuadTreeWorld::ensureQuadTreeBuilt() { - OpenThreads::ScopedLock lock(mQuadTreeMutex); + std::lock_guard lock(mQuadTreeMutex); if (mQuadTreeBuilt) return; diff --git a/components/terrain/quadtreeworld.hpp b/components/terrain/quadtreeworld.hpp index 47cf461387..4c05efe646 100644 --- a/components/terrain/quadtreeworld.hpp +++ b/components/terrain/quadtreeworld.hpp @@ -4,7 +4,7 @@ #include "world.hpp" #include "terraingrid.hpp" -#include +#include namespace osg { @@ -61,7 +61,7 @@ namespace Terrain std::vector mChunkManagers; - OpenThreads::Mutex mQuadTreeMutex; + std::mutex mQuadTreeMutex; bool mQuadTreeBuilt; float mLodFactor; int mVertexLodMod; diff --git a/extern/osg-ffmpeg-videoplayer/videostate.cpp b/extern/osg-ffmpeg-videoplayer/videostate.cpp index 014c5c4f55..c176fe0f29 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.cpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include @@ -95,14 +97,14 @@ void PacketQueue::put(AVPacket *pkt) this->last_pkt = pkt1; this->nb_packets++; this->size += pkt1->pkt.size; - this->cond.signal(); + this->cond.notify_one(); this->mutex.unlock(); } int PacketQueue::get(AVPacket *pkt, VideoState *is) { - OpenThreads::ScopedLock lock(this->mutex); + std::unique_lock lock(this->mutex); while(!is->mQuit) { AVPacketList *pkt1 = this->first_pkt; @@ -122,7 +124,7 @@ int PacketQueue::get(AVPacket *pkt, VideoState *is) if(this->flushing) break; - this->cond.wait(&this->mutex); + this->cond.wait(lock); } return -1; @@ -131,7 +133,7 @@ int PacketQueue::get(AVPacket *pkt, VideoState *is) void PacketQueue::flush() { this->flushing = true; - this->cond.signal(); + this->cond.notify_one(); } void PacketQueue::clear() @@ -226,7 +228,7 @@ void VideoState::video_display(VideoPicture *vp) void VideoState::video_refresh() { - OpenThreads::ScopedLock lock(this->pictq_mutex); + std::lock_guard lock(this->pictq_mutex); if(this->pictq_size == 0) return; @@ -238,7 +240,7 @@ void VideoState::video_refresh() this->pictq_rindex = (pictq_rindex+1) % VIDEO_PICTURE_ARRAY_SIZE; this->frame_last_pts = vp->pts; this->pictq_size--; - this->pictq_cond.signal(); + this->pictq_cond.notify_one(); } else { @@ -268,7 +270,7 @@ void VideoState::video_refresh() // update queue for next picture this->pictq_size--; this->pictq_rindex = (this->pictq_rindex+1) % VIDEO_PICTURE_ARRAY_SIZE; - this->pictq_cond.signal(); + this->pictq_cond.notify_one(); } } @@ -279,9 +281,9 @@ int VideoState::queue_picture(AVFrame *pFrame, double pts) /* wait until we have a new pic */ { - OpenThreads::ScopedLock lock(this->pictq_mutex); + std::unique_lock lock(this->pictq_mutex); while(this->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE && !this->mQuit) - this->pictq_cond.wait(&this->pictq_mutex, 1); + this->pictq_cond.wait_for(lock, std::chrono::milliseconds(1)); } if(this->mQuit) return -1; @@ -340,16 +342,21 @@ double VideoState::synchronize_video(AVFrame *src_frame, double pts) return pts; } -class VideoThread : public OpenThreads::Thread +class VideoThread { public: VideoThread(VideoState* self) : mVideoState(self) + , mThread([this] { run(); }) { - start(); } - virtual void run() + ~VideoThread() + { + mThread.join(); + } + + void run() { VideoState* self = mVideoState; AVPacket pkt1, *packet = &pkt1; @@ -408,18 +415,24 @@ public: private: VideoState* mVideoState; + std::thread mThread; }; -class ParseThread : public OpenThreads::Thread +class ParseThread { public: ParseThread(VideoState* self) : mVideoState(self) + , mThread([this] { run(); }) + { + } + + ~ParseThread() { - start(); + mThread.join(); } - virtual void run() + void run() { VideoState* self = mVideoState; @@ -503,7 +516,7 @@ public: if((self->audio_st && self->audioq.size > MAX_AUDIOQ_SIZE) || (self->video_st && self->videoq.size > MAX_VIDEOQ_SIZE)) { - OpenThreads::Thread::microSleep(10 * 1000); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); continue; } @@ -534,6 +547,7 @@ public: private: VideoState* mVideoState; + std::thread mThread; }; @@ -712,12 +726,10 @@ void VideoState::deinit() if (this->parse_thread.get()) { - this->parse_thread->join(); this->parse_thread.reset(); } if (this->video_thread.get()) { - this->video_thread->join(); this->video_thread.reset(); } @@ -816,7 +828,7 @@ ExternalClock::ExternalClock() void ExternalClock::setPaused(bool paused) { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); if (mPaused == paused) return; if (paused) @@ -830,7 +842,7 @@ void ExternalClock::setPaused(bool paused) uint64_t ExternalClock::get() { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); if (mPaused) return mPausedAt; else @@ -839,7 +851,7 @@ uint64_t ExternalClock::get() void ExternalClock::set(uint64_t time) { - OpenThreads::ScopedLock lock(mMutex); + std::lock_guard lock(mMutex); mTimeBase = av_gettime() - time; mPausedAt = time; } diff --git a/extern/osg-ffmpeg-videoplayer/videostate.hpp b/extern/osg-ffmpeg-videoplayer/videostate.hpp index 54519f428d..984050cd6f 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.hpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.hpp @@ -6,10 +6,8 @@ #include #include #include - -#include -#include -#include +#include +#include #include namespace osg @@ -64,7 +62,7 @@ struct ExternalClock uint64_t mPausedAt; bool mPaused; - OpenThreads::Mutex mMutex; + std::mutex mMutex; void setPaused(bool paused); uint64_t get(); @@ -83,8 +81,8 @@ struct PacketQueue { std::atomic nb_packets; std::atomic size; - OpenThreads::Mutex mutex; - OpenThreads::Condition cond; + std::mutex mutex; + std::condition_variable cond; void put(AVPacket *pkt); int get(AVPacket *pkt, VideoState *is); @@ -164,8 +162,8 @@ struct VideoState { VideoPicture pictq[VIDEO_PICTURE_ARRAY_SIZE]; AVFrame* rgbaFrame; // used as buffer for the frame converted from its native format to RGBA int pictq_size, pictq_rindex, pictq_windex; - OpenThreads::Mutex pictq_mutex; - OpenThreads::Condition pictq_cond; + std::mutex pictq_mutex; + std::condition_variable pictq_cond; std::unique_ptr parse_thread; std::unique_ptr video_thread;