Replace OpenThreads by std types

pull/2932/head
elsid 5 years ago
parent 999325ab44
commit 40ad87bc4d
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -216,7 +216,6 @@ endif(APPLE)
target_link_libraries(openmw-cs target_link_libraries(openmw-cs
${OSG_LIBRARIES} ${OSG_LIBRARIES}
${OPENTHREADS_LIBRARIES}
${OSGTEXT_LIBRARIES} ${OSGTEXT_LIBRARIES}
${OSGUTIL_LIBRARIES} ${OSGUTIL_LIBRARIES}
${OSGVIEWER_LIBRARIES} ${OSGVIEWER_LIBRARIES}

@ -1,5 +1,8 @@
#include "scenewidget.hpp" #include "scenewidget.hpp"
#include <chrono>
#include <thread>
#include <QEvent> #include <QEvent>
#include <QResizeEvent> #include <QResizeEvent>
#include <QTimer> #include <QTimer>
@ -184,7 +187,7 @@ void CompositeViewer::update()
double minFrameTime = _runMaxFrameRate > 0.0 ? 1.0 / _runMaxFrameRate : 0.0; double minFrameTime = _runMaxFrameRate > 0.0 ? 1.0 / _runMaxFrameRate : 0.0;
if (dt < minFrameTime) if (dt < minFrameTime)
{ {
OpenThreads::Thread::microSleep(1000*1000*(minFrameTime-dt)); std::this_thread::sleep_for(std::chrono::duration<double>(minFrameTime - dt));
} }
} }

@ -123,7 +123,6 @@ include_directories(
target_link_libraries(openmw target_link_libraries(openmw
${OSG_LIBRARIES} ${OSG_LIBRARIES}
${OPENTHREADS_LIBRARIES}
${OSGPARTICLE_LIBRARIES} ${OSGPARTICLE_LIBRARIES}
${OSGUTIL_LIBRARIES} ${OSGUTIL_LIBRARIES}
${OSGDB_LIBRARIES} ${OSGDB_LIBRARIES}

@ -2,6 +2,8 @@
#include <iomanip> #include <iomanip>
#include <fstream> #include <fstream>
#include <chrono>
#include <thread>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
@ -762,7 +764,7 @@ void OMW::Engine::go()
if (!frame(dt)) if (!frame(dt))
{ {
OpenThreads::Thread::microSleep(5000); std::this_thread::sleep_for(std::chrono::milliseconds(5));
continue; continue;
} }
else else

@ -1,8 +1,8 @@
#include "environment.hpp" #include "environment.hpp"
#include <cassert> #include <cassert>
#include <chrono>
#include <OpenThreads/Thread> #include <thread>
#include "world.hpp" #include "world.hpp"
#include "scriptmanager.hpp" #include "scriptmanager.hpp"
@ -99,7 +99,7 @@ void MWBase::Environment::limitFrameRate(double dt) const
double minFrameTime = 1.0 / static_cast<double>(mFrameRateLimit); double minFrameTime = 1.0 / static_cast<double>(mFrameRateLimit);
if (thisFrameTime < minFrameTime) if (thisFrameTime < minFrameTime)
{ {
OpenThreads::Thread::microSleep(1000*1000*(minFrameTime-thisFrameTime)); std::this_thread::sleep_for(std::chrono::duration<double>(minFrameTime - thisFrameTime));
} }
} }
} }

@ -1,6 +1,8 @@
#include "windowmanagerimp.hpp" #include "windowmanagerimp.hpp"
#include <cassert> #include <cassert>
#include <chrono>
#include <thread>
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
@ -751,7 +753,7 @@ namespace MWGui
MWBase::Environment::get().getInputManager()->update(dt, true, false); MWBase::Environment::get().getInputManager()->update(dt, true, false);
if (!mWindowVisible) if (!mWindowVisible)
OpenThreads::Thread::microSleep(5000); std::this_thread::sleep_for(std::chrono::milliseconds(5));
else else
{ {
mViewer->eventTraversal(); mViewer->eventTraversal();
@ -1788,7 +1790,7 @@ namespace MWGui
if (!mWindowVisible) if (!mWindowVisible)
{ {
mVideoWidget->pause(); mVideoWidget->pause();
OpenThreads::Thread::microSleep(5000); std::this_thread::sleep_for(std::chrono::milliseconds(5));
} }
else else
{ {

@ -428,7 +428,7 @@ namespace MWRender
if (activeGrid) if (activeGrid)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mRefTrackerMutex); std::lock_guard<std::mutex> lock(mRefTrackerMutex);
for (auto ref : getRefTracker().mBlacklist) for (auto ref : getRefTracker().mBlacklist)
refs.erase(ref); refs.erase(ref);
} }
@ -464,7 +464,7 @@ namespace MWRender
float dSqr = (viewPoint - pos).length2(); float dSqr = (viewPoint - pos).length2();
if (!activeGrid) if (!activeGrid)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSizeCacheMutex); std::lock_guard<std::mutex> lock(mSizeCacheMutex);
SizeCache::iterator found = mSizeCache.find(pair.first); SizeCache::iterator found = mSizeCache.find(pair.first);
if (found != mSizeCache.end() && found->second < dSqr*minSize*minSize) if (found != mSizeCache.end() && found->second < dSqr*minSize*minSize)
continue; continue;
@ -501,7 +501,7 @@ namespace MWRender
} }
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mRefTrackerMutex); std::lock_guard<std::mutex> lock(mRefTrackerMutex);
if (getRefTracker().mDisabled.count(pair.first)) if (getRefTracker().mDisabled.count(pair.first))
continue; continue;
} }
@ -509,7 +509,7 @@ namespace MWRender
float radius2 = cnode->getBound().radius2() * ref.mScale*ref.mScale; float radius2 = cnode->getBound().radius2() * ref.mScale*ref.mScale;
if (radius2 < dSqr*minSize*minSize && !activeGrid) if (radius2 < dSqr*minSize*minSize && !activeGrid)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSizeCacheMutex); std::lock_guard<std::mutex> lock(mSizeCacheMutex);
mSizeCache[pair.first] = radius2; mSizeCache[pair.first] = radius2;
continue; continue;
} }
@ -685,7 +685,7 @@ namespace MWRender
return false; return false;
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mRefTrackerMutex); std::lock_guard<std::mutex> lock(mRefTrackerMutex);
if (enabled && !getWritableRefTracker().mDisabled.erase(refnum)) return false; if (enabled && !getWritableRefTracker().mDisabled.erase(refnum)) return false;
if (!enabled && !getWritableRefTracker().mDisabled.insert(refnum).second) return false; if (!enabled && !getWritableRefTracker().mDisabled.insert(refnum).second) return false;
if (mRefTrackerLocked) return false; if (mRefTrackerLocked) return false;
@ -706,7 +706,7 @@ namespace MWRender
return false; return false;
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mRefTrackerMutex); std::lock_guard<std::mutex> lock(mRefTrackerMutex);
if (!getWritableRefTracker().mBlacklist.insert(refnum).second) return false; if (!getWritableRefTracker().mBlacklist.insert(refnum).second) return false;
if (mRefTrackerLocked) return false; if (mRefTrackerLocked) return false;
} }
@ -724,7 +724,7 @@ namespace MWRender
void ObjectPaging::clear() void ObjectPaging::clear()
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mRefTrackerMutex); std::lock_guard<std::mutex> lock(mRefTrackerMutex);
mRefTrackerNew.mDisabled.clear(); mRefTrackerNew.mDisabled.clear();
mRefTrackerNew.mBlacklist.clear(); mRefTrackerNew.mBlacklist.clear();
mRefTrackerLocked = true; mRefTrackerLocked = true;
@ -734,7 +734,7 @@ namespace MWRender
{ {
if (!mRefTrackerLocked) return false; if (!mRefTrackerLocked) return false;
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mRefTrackerMutex); std::lock_guard<std::mutex> lock(mRefTrackerMutex);
mRefTrackerLocked = false; mRefTrackerLocked = false;
if (mRefTracker == mRefTrackerNew) if (mRefTracker == mRefTrackerNew)
return false; return false;

@ -5,7 +5,7 @@
#include <components/resource/resourcemanager.hpp> #include <components/resource/resourcemanager.hpp>
#include <components/esm/loadcell.hpp> #include <components/esm/loadcell.hpp>
#include <OpenThreads/Mutex> #include <mutex>
namespace Resource namespace Resource
{ {
@ -58,7 +58,7 @@ namespace MWRender
float mMinSizeMergeFactor; float mMinSizeMergeFactor;
float mMinSizeCostMultiplier; float mMinSizeCostMultiplier;
OpenThreads::Mutex mRefTrackerMutex; std::mutex mRefTrackerMutex;
struct RefTracker struct RefTracker
{ {
std::set<ESM::RefNum> mDisabled; std::set<ESM::RefNum> mDisabled;
@ -72,7 +72,7 @@ namespace MWRender
const RefTracker& getRefTracker() const { return mRefTracker; } const RefTracker& getRefTracker() const { return mRefTracker; }
RefTracker& getWritableRefTracker() { return mRefTrackerLocked ? mRefTrackerNew : mRefTracker; } RefTracker& getWritableRefTracker() { return mRefTrackerLocked ? mRefTrackerNew : mRefTracker; }
OpenThreads::Mutex mSizeCacheMutex; std::mutex mSizeCacheMutex;
typedef std::map<ESM::RefNum, float> SizeCache; typedef std::map<ESM::RefNum, float> SizeCache;
SizeCache mSizeCache; SizeCache mSizeCache;
}; };

@ -2,6 +2,8 @@
#include <limits> #include <limits>
#include <cstdlib> #include <cstdlib>
#include <condition_variable>
#include <mutex>
#include <osg/Light> #include <osg/Light>
#include <osg/LightModel> #include <osg/LightModel>
@ -709,24 +711,24 @@ namespace MWRender
virtual void operator () (osg::RenderInfo& renderInfo) const virtual void operator () (osg::RenderInfo& renderInfo) const
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
if (renderInfo.getState()->getFrameStamp()->getFrameNumber() >= mFrame) if (renderInfo.getState()->getFrameStamp()->getFrameNumber() >= mFrame)
{ {
mDone = true; mDone = true;
mCondition.signal(); mCondition.notify_one();
} }
} }
void waitTillDone() void waitTillDone()
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::unique_lock<std::mutex> lock(mMutex);
if (mDone) if (mDone)
return; return;
mCondition.wait(&mMutex); mCondition.wait(lock);
} }
mutable OpenThreads::Condition mCondition; mutable std::condition_variable mCondition;
mutable OpenThreads::Mutex mMutex; mutable std::mutex mMutex;
mutable bool mDone; mutable bool mDone;
unsigned int mFrame; unsigned int mFrame;
}; };

@ -4,6 +4,10 @@
#include <memory> #include <memory>
#include <array> #include <array>
#include <atomic> #include <atomic>
#include <condition_variable>
#include <thread>
#include <mutex>
#include <chrono>
#include <stdint.h> #include <stdint.h>
@ -11,11 +15,6 @@
#include <components/misc/constants.hpp> #include <components/misc/constants.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <OpenThreads/Thread>
#include <OpenThreads/Condition>
#include <OpenThreads/Mutex>
#include <OpenThreads/ScopedLock>
#include "openal_output.hpp" #include "openal_output.hpp"
#include "sound_decoder.hpp" #include "sound_decoder.hpp"
#include "sound.hpp" #include "sound.hpp"
@ -309,31 +308,33 @@ const ALfloat OpenAL_SoundStream::sBufferLength = 0.125f;
// //
// A background streaming thread (keeps active streams processed) // A background streaming thread (keeps active streams processed)
// //
struct OpenAL_Output::StreamThread : public OpenThreads::Thread { struct OpenAL_Output::StreamThread
{
typedef std::vector<OpenAL_SoundStream*> StreamVec; typedef std::vector<OpenAL_SoundStream*> StreamVec;
StreamVec mStreams; StreamVec mStreams;
std::atomic<bool> mQuitNow; std::atomic<bool> mQuitNow;
OpenThreads::Mutex mMutex; std::mutex mMutex;
OpenThreads::Condition mCondVar; std::condition_variable mCondVar;
std::thread mThread;
StreamThread() StreamThread()
: mQuitNow(false) : mQuitNow(false)
, mThread([this] { run(); })
{ {
start();
} }
~StreamThread() ~StreamThread()
{ {
mQuitNow = true; mQuitNow = true;
mMutex.lock(); mMutex.unlock(); mMutex.lock(); mMutex.unlock();
mCondVar.broadcast(); mCondVar.notify_all();
join(); mThread.join();
} }
// thread entry point // thread entry point
virtual void run() void run()
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::unique_lock<std::mutex> lock(mMutex);
while(!mQuitNow) while(!mQuitNow)
{ {
StreamVec::iterator iter = mStreams.begin(); StreamVec::iterator iter = mStreams.begin();
@ -345,30 +346,30 @@ struct OpenAL_Output::StreamThread : public OpenThreads::Thread {
++iter; ++iter;
} }
mCondVar.wait(&mMutex, 50); mCondVar.wait_for(lock, std::chrono::milliseconds(50));
} }
} }
void add(OpenAL_SoundStream *stream) void add(OpenAL_SoundStream *stream)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
if(std::find(mStreams.begin(), mStreams.end(), stream) == mStreams.end()) if(std::find(mStreams.begin(), mStreams.end(), stream) == mStreams.end())
{ {
mStreams.push_back(stream); mStreams.push_back(stream);
mCondVar.broadcast(); mCondVar.notify_all();
} }
} }
void remove(OpenAL_SoundStream *stream) void remove(OpenAL_SoundStream *stream)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
StreamVec::iterator iter = std::find(mStreams.begin(), mStreams.end(), stream); StreamVec::iterator iter = std::find(mStreams.begin(), mStreams.end(), stream);
if(iter != mStreams.end()) mStreams.erase(iter); if(iter != mStreams.end()) mStreams.erase(iter);
} }
void removeAll() void removeAll()
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
mStreams.clear(); mStreams.clear();
} }
@ -1341,7 +1342,7 @@ double OpenAL_Output::getStreamOffset(Stream *sound)
{ {
if(!sound->mHandle) return 0.0; if(!sound->mHandle) return 0.0;
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle); OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mStreamThread->mMutex); std::lock_guard<std::mutex> lock(mStreamThread->mMutex);
return stream->getStreamOffset(); return stream->getStreamOffset();
} }
@ -1349,7 +1350,7 @@ float OpenAL_Output::getStreamLoudness(Stream *sound)
{ {
if(!sound->mHandle) return 0.0; if(!sound->mHandle) return 0.0;
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle); OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mStreamThread->mMutex); std::lock_guard<std::mutex> lock(mStreamThread->mMutex);
return stream->getCurrentLoudness(); return stream->getCurrentLoudness();
} }
@ -1357,7 +1358,7 @@ bool OpenAL_Output::isStreamPlaying(Stream *sound)
{ {
if(!sound->mHandle) return false; if(!sound->mHandle) return false;
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle); OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mStreamThread->mMutex); std::lock_guard<std::mutex> lock(mStreamThread->mMutex);
return stream->isPlaying(); return stream->isPlaying();
} }

@ -1,6 +1,8 @@
#include "scene.hpp" #include "scene.hpp"
#include <limits> #include <limits>
#include <chrono>
#include <thread>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h> #include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <BulletCollision/CollisionShapes/btCompoundShape.h> #include <BulletCollision/CollisionShapes/btCompoundShape.h>
@ -1143,7 +1145,7 @@ namespace MWWorld
} }
else else
loadingListener->setProgress(0); loadingListener->setProgress(0);
OpenThreads::Thread::microSleep(5000); std::this_thread::sleep_for(std::chrono::milliseconds(5));
} }
} }

@ -2,8 +2,6 @@
#include <set> #include <set>
#include <OpenThreads/ScopedLock>
#include <osg/Image> #include <osg/Image>
#include <osg/Plane> #include <osg/Plane>
@ -548,7 +546,7 @@ namespace ESMTerrain
Terrain::LayerInfo Storage::getLayerInfo(const std::string& texture) Terrain::LayerInfo Storage::getLayerInfo(const std::string& texture)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mLayerInfoMutex); std::lock_guard<std::mutex> lock(mLayerInfoMutex);
// Already have this cached? // Already have this cached?
std::map<std::string, Terrain::LayerInfo>::iterator found = mLayerInfoMap.find(texture); std::map<std::string, Terrain::LayerInfo>::iterator found = mLayerInfoMap.find(texture);

@ -2,8 +2,7 @@
#define COMPONENTS_ESM_TERRAIN_STORAGE_H #define COMPONENTS_ESM_TERRAIN_STORAGE_H
#include <cassert> #include <cassert>
#include <mutex>
#include <OpenThreads/Mutex>
#include <components/terrain/storage.hpp> #include <components/terrain/storage.hpp>
@ -138,7 +137,7 @@ namespace ESMTerrain
std::string getTextureName (UniqueTextureId id); std::string getTextureName (UniqueTextureId id);
std::map<std::string, Terrain::LayerInfo> mLayerInfoMap; std::map<std::string, Terrain::LayerInfo> mLayerInfoMap;
OpenThreads::Mutex mLayerInfoMutex; std::mutex mLayerInfoMutex;
std::string mNormalMapPattern; std::string mNormalMapPattern;
std::string mNormalHeightMapPattern; std::string mNormalHeightMapPattern;

@ -1,5 +1,7 @@
#include "nifloader.hpp" #include "nifloader.hpp"
#include <mutex>
#include <osg/Matrixf> #include <osg/Matrixf>
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
#include <osg/Geometry> #include <osg/Geometry>
@ -1725,8 +1727,8 @@ namespace NifOsg
{ {
typedef std::set<osg::ref_ptr<Attribute>, CompareStateAttribute> Cache; typedef std::set<osg::ref_ptr<Attribute>, CompareStateAttribute> Cache;
static Cache sCache; static Cache sCache;
static OpenThreads::Mutex sMutex; static std::mutex sMutex;
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(sMutex); std::lock_guard<std::mutex> lock(sMutex);
typename Cache::iterator found = sCache.find(attr); typename Cache::iterator found = sCache.find(attr);
if (found == sCache.end()) if (found == sCache.end())
found = sCache.insert(attr).first; found = sCache.insert(attr).first;

@ -21,7 +21,7 @@ namespace Resource
{ {
std::vector<osg::ref_ptr<osg::Object> > objectsToRemove; std::vector<osg::ref_ptr<osg::Object> > objectsToRemove;
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
// Remove unreferenced entries from object cache // Remove unreferenced entries from object cache
ObjectCacheMap::iterator oitr = _objectCache.begin(); ObjectCacheMap::iterator oitr = _objectCache.begin();
@ -45,7 +45,7 @@ namespace Resource
void MultiObjectCache::clear() void MultiObjectCache::clear()
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
_objectCache.clear(); _objectCache.clear();
} }
@ -56,13 +56,13 @@ namespace Resource
OSG_ALWAYS << " trying to add NULL object to cache for " << filename << std::endl; OSG_ALWAYS << " trying to add NULL object to cache for " << filename << std::endl;
return; return;
} }
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
_objectCache.insert(std::make_pair(filename, object)); _objectCache.insert(std::make_pair(filename, object));
} }
osg::ref_ptr<osg::Object> MultiObjectCache::takeFromObjectCache(const std::string &fileName) osg::ref_ptr<osg::Object> MultiObjectCache::takeFromObjectCache(const std::string &fileName)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
ObjectCacheMap::iterator found = _objectCache.find(fileName); ObjectCacheMap::iterator found = _objectCache.find(fileName);
if (found == _objectCache.end()) if (found == _objectCache.end())
return osg::ref_ptr<osg::Object>(); return osg::ref_ptr<osg::Object>();
@ -76,7 +76,7 @@ namespace Resource
void MultiObjectCache::releaseGLObjects(osg::State *state) void MultiObjectCache::releaseGLObjects(osg::State *state)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
for(ObjectCacheMap::iterator itr = _objectCache.begin(); for(ObjectCacheMap::iterator itr = _objectCache.begin();
itr != _objectCache.end(); itr != _objectCache.end();
@ -89,7 +89,7 @@ namespace Resource
unsigned int MultiObjectCache::getCacheSize() const unsigned int MultiObjectCache::getCacheSize() const
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
return _objectCache.size(); return _objectCache.size();
} }

@ -3,6 +3,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <mutex>
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <osg/Referenced> #include <osg/Referenced>
@ -43,7 +44,7 @@ namespace Resource
typedef std::multimap<std::string, osg::ref_ptr<osg::Object> > ObjectCacheMap; typedef std::multimap<std::string, osg::ref_ptr<osg::Object> > ObjectCacheMap;
ObjectCacheMap _objectCache; ObjectCacheMap _objectCache;
mutable OpenThreads::Mutex _objectCacheMutex; mutable std::mutex _objectCacheMutex;
}; };

@ -26,6 +26,7 @@
#include <string> #include <string>
#include <map> #include <map>
#include <mutex>
namespace osg namespace osg
{ {
@ -53,7 +54,7 @@ class GenericObjectCache : public osg::Referenced
void updateTimeStampOfObjectsInCacheWithExternalReferences(double referenceTime) void updateTimeStampOfObjectsInCacheWithExternalReferences(double referenceTime)
{ {
// look for objects with external references and update their time stamp. // look for objects with external references and update their time stamp.
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
for(typename ObjectCacheMap::iterator itr=_objectCache.begin(); itr!=_objectCache.end(); ++itr) for(typename ObjectCacheMap::iterator itr=_objectCache.begin(); itr!=_objectCache.end(); ++itr)
{ {
// If ref count is greater than 1, the object has an external reference. // If ref count is greater than 1, the object has an external reference.
@ -71,7 +72,7 @@ class GenericObjectCache : public osg::Referenced
{ {
std::vector<osg::ref_ptr<osg::Object> > objectsToRemove; std::vector<osg::ref_ptr<osg::Object> > objectsToRemove;
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
// Remove expired entries from object cache // Remove expired entries from object cache
typename ObjectCacheMap::iterator oitr = _objectCache.begin(); typename ObjectCacheMap::iterator oitr = _objectCache.begin();
while(oitr != _objectCache.end()) 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.*/ /** Remove all objects in the cache regardless of having external references or expiry times.*/
void clear() void clear()
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
_objectCache.clear(); _objectCache.clear();
} }
/** Add a key,object,timestamp triple to the Registry::ObjectCache.*/ /** Add a key,object,timestamp triple to the Registry::ObjectCache.*/
void addEntryToObjectCache(const KeyType& key, osg::Object* object, double timestamp = 0.0) void addEntryToObjectCache(const KeyType& key, osg::Object* object, double timestamp = 0.0)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
_objectCache[key]=ObjectTimeStampPair(object,timestamp); _objectCache[key]=ObjectTimeStampPair(object,timestamp);
} }
/** Remove Object from cache.*/ /** Remove Object from cache.*/
void removeFromObjectCache(const KeyType& key) void removeFromObjectCache(const KeyType& key)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
typename ObjectCacheMap::iterator itr = _objectCache.find(key); typename ObjectCacheMap::iterator itr = _objectCache.find(key);
if (itr!=_objectCache.end()) _objectCache.erase(itr); if (itr!=_objectCache.end()) _objectCache.erase(itr);
} }
@ -114,7 +115,7 @@ class GenericObjectCache : public osg::Referenced
/** Get an ref_ptr<Object> from the object cache*/ /** Get an ref_ptr<Object> from the object cache*/
osg::ref_ptr<osg::Object> getRefFromObjectCache(const KeyType& key) osg::ref_ptr<osg::Object> getRefFromObjectCache(const KeyType& key)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
typename ObjectCacheMap::iterator itr = _objectCache.find(key); typename ObjectCacheMap::iterator itr = _objectCache.find(key);
if (itr!=_objectCache.end()) if (itr!=_objectCache.end())
return itr->second.first; 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. */ /** Check if an object is in the cache, and if it is, update its usage time stamp. */
bool checkInObjectCache(const KeyType& key, double timeStamp) bool checkInObjectCache(const KeyType& key, double timeStamp)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
typename ObjectCacheMap::iterator itr = _objectCache.find(key); typename ObjectCacheMap::iterator itr = _objectCache.find(key);
if (itr!=_objectCache.end()) if (itr!=_objectCache.end())
{ {
@ -137,7 +138,7 @@ class GenericObjectCache : public osg::Referenced
/** call releaseGLObjects on all objects attached to the object cache.*/ /** call releaseGLObjects on all objects attached to the object cache.*/
void releaseGLObjects(osg::State* state) void releaseGLObjects(osg::State* state)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
for(typename ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); ++itr) for(typename ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); ++itr)
{ {
osg::Object* object = itr->second.first.get(); 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. */ /** call node->accept(nv); for all nodes in the objectCache. */
void accept(osg::NodeVisitor& nv) void accept(osg::NodeVisitor& nv)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
for(typename ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); ++itr) for(typename ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); ++itr)
{ {
osg::Object* object = itr->second.first.get(); osg::Object* object = itr->second.first.get();
@ -165,7 +166,7 @@ class GenericObjectCache : public osg::Referenced
template <class Functor> template <class Functor>
void call(Functor& f) void call(Functor& f)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
for (typename ObjectCacheMap::iterator it = _objectCache.begin(); it != _objectCache.end(); ++it) for (typename ObjectCacheMap::iterator it = _objectCache.begin(); it != _objectCache.end(); ++it)
f(it->first, it->second.first.get()); f(it->first, it->second.first.get());
} }
@ -173,7 +174,7 @@ class GenericObjectCache : public osg::Referenced
/** Get the number of objects in the cache. */ /** Get the number of objects in the cache. */
unsigned int getCacheSize() const unsigned int getCacheSize() const
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
return _objectCache.size(); return _objectCache.size();
} }
@ -185,7 +186,7 @@ class GenericObjectCache : public osg::Referenced
typedef std::map<KeyType, ObjectTimeStampPair > ObjectCacheMap; typedef std::map<KeyType, ObjectTimeStampPair > ObjectCacheMap;
ObjectCacheMap _objectCache; ObjectCacheMap _objectCache;
mutable OpenThreads::Mutex _objectCacheMutex; mutable std::mutex _objectCacheMutex;
}; };

@ -126,7 +126,7 @@ namespace Resource
void clearCache() void clearCache()
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_listMutex); std::lock_guard<OpenThreads::Mutex> lock(_listMutex);
_sharedTextureList.clear(); _sharedTextureList.clear();
_sharedStateSetList.clear(); _sharedStateSetList.clear();
} }
@ -625,7 +625,7 @@ namespace Resource
mShaderManager->releaseGLObjects(state); mShaderManager->releaseGLObjects(state);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSharedStateMutex); std::lock_guard<std::mutex> lock(mSharedStateMutex);
mSharedStateManager->releaseGLObjects(state); mSharedStateManager->releaseGLObjects(state);
} }
@ -717,7 +717,7 @@ namespace Resource
if (mIncrementalCompileOperation) if (mIncrementalCompileOperation)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*mIncrementalCompileOperation->getToCompiledMutex()); std::lock_guard<OpenThreads::Mutex> lock(*mIncrementalCompileOperation->getToCompiledMutex());
osgUtil::IncrementalCompileOperation::CompileSets& sets = mIncrementalCompileOperation->getToCompile(); osgUtil::IncrementalCompileOperation::CompileSets& sets = mIncrementalCompileOperation->getToCompile();
for(osgUtil::IncrementalCompileOperation::CompileSets::iterator it = sets.begin(); it != sets.end();) for(osgUtil::IncrementalCompileOperation::CompileSets::iterator it = sets.begin(); it != sets.end();)
{ {
@ -738,7 +738,7 @@ namespace Resource
{ {
ResourceManager::clearCache(); ResourceManager::clearCache();
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSharedStateMutex); std::lock_guard<std::mutex> lock(mSharedStateMutex);
mSharedStateManager->clearCache(); mSharedStateManager->clearCache();
mInstanceCache->clear(); mInstanceCache->clear();
} }
@ -747,12 +747,12 @@ namespace Resource
{ {
if (mIncrementalCompileOperation) if (mIncrementalCompileOperation)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*mIncrementalCompileOperation->getToCompiledMutex()); std::lock_guard<OpenThreads::Mutex> lock(*mIncrementalCompileOperation->getToCompiledMutex());
stats->setAttribute(frameNumber, "Compiling", mIncrementalCompileOperation->getToCompile().size()); stats->setAttribute(frameNumber, "Compiling", mIncrementalCompileOperation->getToCompile().size());
} }
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSharedStateMutex); std::lock_guard<std::mutex> lock(mSharedStateMutex);
stats->setAttribute(frameNumber, "Texture", mSharedStateManager->getNumSharedTextures()); stats->setAttribute(frameNumber, "Texture", mSharedStateManager->getNumSharedTextures());
stats->setAttribute(frameNumber, "StateSet", mSharedStateManager->getNumSharedStateSets()); stats->setAttribute(frameNumber, "StateSet", mSharedStateManager->getNumSharedStateSets());
} }

@ -4,6 +4,7 @@
#include <string> #include <string>
#include <map> #include <map>
#include <memory> #include <memory>
#include <mutex>
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <osg/Node> #include <osg/Node>
@ -159,7 +160,7 @@ namespace Resource
osg::ref_ptr<MultiObjectCache> mInstanceCache; osg::ref_ptr<MultiObjectCache> mInstanceCache;
osg::ref_ptr<Resource::SharedStateManager> mSharedStateManager; osg::ref_ptr<Resource::SharedStateManager> mSharedStateManager;
mutable OpenThreads::Mutex mSharedStateMutex; mutable std::mutex mSharedStateMutex;
Resource::ImageManager* mImageManager; Resource::ImageManager* mImageManager;
Resource::NifFileManager* mNifFileManager; Resource::NifFileManager* mNifFileManager;

@ -891,7 +891,7 @@ MWShadowTechnique::ViewDependentData* MWShadowTechnique::createViewDependentData
MWShadowTechnique::ViewDependentData* MWShadowTechnique::getViewDependentData(osgUtil::CullVisitor* cv) MWShadowTechnique::ViewDependentData* MWShadowTechnique::getViewDependentData(osgUtil::CullVisitor* cv)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDependentDataMapMutex); std::lock_guard<std::mutex> lock(_viewDependentDataMapMutex);
ViewDependentDataMap::iterator itr = _viewDependentDataMap.find(cv); ViewDependentDataMap::iterator itr = _viewDependentDataMap.find(cv);
if (itr!=_viewDependentDataMap.end()) return itr->second.get(); 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); std::string validRegionUniformName = "validRegionMatrix" + std::to_string(sm_i);
osg::ref_ptr<osg::Uniform> validRegionUniform; osg::ref_ptr<osg::Uniform> validRegionUniform;
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_accessUniformsAndProgramMutex); std::lock_guard<std::mutex> lock(_accessUniformsAndProgramMutex);
for (auto uniform : _uniforms) for (auto uniform : _uniforms)
{ {
@ -1467,7 +1467,7 @@ void MWShadowTechnique::createShaders()
unsigned int _baseTextureUnit = 0; unsigned int _baseTextureUnit = 0;
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_accessUniformsAndProgramMutex); std::lock_guard<std::mutex> lock(_accessUniformsAndProgramMutex);
_shadowCastingStateSet = new osg::StateSet; _shadowCastingStateSet = new osg::StateSet;
@ -2980,7 +2980,7 @@ osg::StateSet* MWShadowTechnique::selectStateSetForRenderingShadow(ViewDependent
osg::ref_ptr<osg::StateSet> stateset = vdd.getStateSet(); osg::ref_ptr<osg::StateSet> stateset = vdd.getStateSet();
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_accessUniformsAndProgramMutex); std::lock_guard<std::mutex> lock(_accessUniformsAndProgramMutex);
vdd.getStateSet()->clear(); vdd.getStateSet()->clear();
@ -3057,7 +3057,7 @@ void MWShadowTechnique::resizeGLObjectBuffers(unsigned int /*maxSize*/)
void MWShadowTechnique::releaseGLObjects(osg::State* state) const void MWShadowTechnique::releaseGLObjects(osg::State* state) const
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_viewDependentDataMapMutex); std::lock_guard<std::mutex> lock(_viewDependentDataMapMutex);
for(ViewDependentDataMap::const_iterator itr = _viewDependentDataMap.begin(); for(ViewDependentDataMap::const_iterator itr = _viewDependentDataMap.begin();
itr != _viewDependentDataMap.end(); itr != _viewDependentDataMap.end();
++itr) ++itr)

@ -19,6 +19,8 @@
#ifndef COMPONENTS_SCENEUTIL_MWSHADOWTECHNIQUE_H #ifndef COMPONENTS_SCENEUTIL_MWSHADOWTECHNIQUE_H
#define COMPONENTS_SCENEUTIL_MWSHADOWTECHNIQUE_H 1 #define COMPONENTS_SCENEUTIL_MWSHADOWTECHNIQUE_H 1
#include <mutex>
#include <osg/Camera> #include <osg/Camera>
#include <osg/Material> #include <osg/Material>
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
@ -234,7 +236,7 @@ namespace SceneUtil {
virtual ~MWShadowTechnique(); virtual ~MWShadowTechnique();
typedef std::map< osgUtil::CullVisitor*, osg::ref_ptr<ViewDependentData> > ViewDependentDataMap; typedef std::map< osgUtil::CullVisitor*, osg::ref_ptr<ViewDependentData> > ViewDependentDataMap;
mutable OpenThreads::Mutex _viewDependentDataMapMutex; mutable std::mutex _viewDependentDataMapMutex;
ViewDependentDataMap _viewDependentDataMap; ViewDependentDataMap _viewDependentDataMap;
osg::ref_ptr<osg::StateSet> _shadowRecievingPlaceholderStateSet; osg::ref_ptr<osg::StateSet> _shadowRecievingPlaceholderStateSet;
@ -245,7 +247,7 @@ namespace SceneUtil {
osg::ref_ptr<osg::Texture2D> _fallbackShadowMapTexture; osg::ref_ptr<osg::Texture2D> _fallbackShadowMapTexture;
typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms; typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms;
mutable OpenThreads::Mutex _accessUniformsAndProgramMutex; mutable std::mutex _accessUniformsAndProgramMutex;
Uniforms _uniforms; Uniforms _uniforms;
osg::ref_ptr<osg::Program> _program; osg::ref_ptr<osg::Program> _program;

@ -273,7 +273,7 @@ namespace Shader
osg::ref_ptr<osg::Shader> ShaderManager::getShader(const std::string &templateName, const ShaderManager::DefineMap &defines, osg::Shader::Type shaderType) osg::ref_ptr<osg::Shader> ShaderManager::getShader(const std::string &templateName, const ShaderManager::DefineMap &defines, osg::Shader::Type shaderType)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
// read the template if we haven't already // read the template if we haven't already
TemplateMap::iterator templateIt = mShaderTemplates.find(templateName); TemplateMap::iterator templateIt = mShaderTemplates.find(templateName);
@ -323,7 +323,7 @@ namespace Shader
osg::ref_ptr<osg::Program> ShaderManager::getProgram(osg::ref_ptr<osg::Shader> vertexShader, osg::ref_ptr<osg::Shader> fragmentShader) osg::ref_ptr<osg::Program> ShaderManager::getProgram(osg::ref_ptr<osg::Shader> vertexShader, osg::ref_ptr<osg::Shader> fragmentShader)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
ProgramMap::iterator found = mPrograms.find(std::make_pair(vertexShader, fragmentShader)); ProgramMap::iterator found = mPrograms.find(std::make_pair(vertexShader, fragmentShader));
if (found == mPrograms.end()) if (found == mPrograms.end())
{ {
@ -362,7 +362,7 @@ namespace Shader
void ShaderManager::releaseGLObjects(osg::State *state) void ShaderManager::releaseGLObjects(osg::State *state)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
for (auto shader : mShaders) for (auto shader : mShaders)
{ {
if (shader.second != nullptr) if (shader.second != nullptr)

@ -3,6 +3,7 @@
#include <string> #include <string>
#include <map> #include <map>
#include <mutex>
#include <osg/ref_ptr> #include <osg/ref_ptr>
@ -10,8 +11,6 @@
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
#include <OpenThreads/Mutex>
namespace Shader namespace Shader
{ {
@ -63,7 +62,7 @@ namespace Shader
typedef std::map<std::pair<osg::ref_ptr<osg::Shader>, osg::ref_ptr<osg::Shader> >, osg::ref_ptr<osg::Program> > ProgramMap; typedef std::map<std::pair<osg::ref_ptr<osg::Shader>, osg::ref_ptr<osg::Shader> >, osg::ref_ptr<osg::Program> > ProgramMap;
ProgramMap mPrograms; ProgramMap mPrograms;
OpenThreads::Mutex mMutex; std::mutex mMutex;
const osg::ref_ptr<osg::Uniform> mShadowMapAlphaTestEnableUniform = new osg::Uniform(); const osg::ref_ptr<osg::Uniform> mShadowMapAlphaTestEnableUniform = new osg::Uniform();
const osg::ref_ptr<osg::Uniform> mShadowMapAlphaTestDisableUniform = new osg::Uniform(); const osg::ref_ptr<osg::Uniform> mShadowMapAlphaTestDisableUniform = new osg::Uniform();

@ -2,8 +2,6 @@
#include <cassert> #include <cassert>
#include <OpenThreads/ScopedLock>
#include <osg/PrimitiveSet> #include <osg/PrimitiveSet>
#include "defs.hpp" #include "defs.hpp"
@ -180,7 +178,7 @@ namespace Terrain
osg::ref_ptr<osg::Vec2Array> BufferCache::getUVBuffer(unsigned int numVerts) osg::ref_ptr<osg::Vec2Array> BufferCache::getUVBuffer(unsigned int numVerts)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mUvBufferMutex); std::lock_guard<std::mutex> lock(mUvBufferMutex);
if (mUvBufferMap.find(numVerts) != mUvBufferMap.end()) if (mUvBufferMap.find(numVerts) != mUvBufferMap.end())
{ {
return mUvBufferMap[numVerts]; return mUvBufferMap[numVerts];
@ -210,7 +208,7 @@ namespace Terrain
osg::ref_ptr<osg::DrawElements> BufferCache::getIndexBuffer(unsigned int numVerts, unsigned int flags) osg::ref_ptr<osg::DrawElements> BufferCache::getIndexBuffer(unsigned int numVerts, unsigned int flags)
{ {
std::pair<int, int> id = std::make_pair(numVerts, flags); std::pair<int, int> id = std::make_pair(numVerts, flags);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mIndexBufferMutex); std::lock_guard<std::mutex> lock(mIndexBufferMutex);
if (mIndexBufferMap.find(id) != mIndexBufferMap.end()) if (mIndexBufferMap.find(id) != mIndexBufferMap.end())
{ {
@ -234,11 +232,11 @@ namespace Terrain
void BufferCache::clearCache() void BufferCache::clearCache()
{ {
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mIndexBufferMutex); std::lock_guard<std::mutex> lock(mIndexBufferMutex);
mIndexBufferMap.clear(); mIndexBufferMap.clear();
} }
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mUvBufferMutex); std::lock_guard<std::mutex> lock(mUvBufferMutex);
mUvBufferMap.clear(); mUvBufferMap.clear();
} }
} }
@ -246,12 +244,12 @@ namespace Terrain
void BufferCache::releaseGLObjects(osg::State *state) void BufferCache::releaseGLObjects(osg::State *state)
{ {
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mIndexBufferMutex); std::lock_guard<std::mutex> lock(mIndexBufferMutex);
for (auto indexbuffer : mIndexBufferMap) for (auto indexbuffer : mIndexBufferMap)
indexbuffer.second->releaseGLObjects(state); indexbuffer.second->releaseGLObjects(state);
} }
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mUvBufferMutex); std::lock_guard<std::mutex> lock(mUvBufferMutex);
for (auto uvbuffer : mUvBufferMap) for (auto uvbuffer : mUvBufferMap)
uvbuffer.second->releaseGLObjects(state); uvbuffer.second->releaseGLObjects(state);
} }

@ -6,6 +6,7 @@
#include <osg/PrimitiveSet> #include <osg/PrimitiveSet>
#include <map> #include <map>
#include <mutex>
namespace Terrain namespace Terrain
{ {
@ -30,10 +31,10 @@ namespace Terrain
// Index buffers are shared across terrain batches where possible. There is one index buffer for each // 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. // combination of LOD deltas and index buffer LOD we may need.
std::map<std::pair<int, int>, osg::ref_ptr<osg::DrawElements> > mIndexBufferMap; std::map<std::pair<int, int>, osg::ref_ptr<osg::DrawElements> > mIndexBufferMap;
OpenThreads::Mutex mIndexBufferMutex; std::mutex mIndexBufferMutex;
std::map<int, osg::ref_ptr<osg::Vec2Array> > mUvBufferMap; std::map<int, osg::ref_ptr<osg::Vec2Array> > mUvBufferMap;
OpenThreads::Mutex mUvBufferMutex; std::mutex mUvBufferMutex;
}; };
} }

@ -1,7 +1,5 @@
#include "compositemaprenderer.hpp" #include "compositemaprenderer.hpp"
#include <OpenThreads/ScopedLock>
#include <osg/FrameBufferObject> #include <osg/FrameBufferObject>
#include <osg/Texture2D> #include <osg/Texture2D>
#include <osg/RenderInfo> #include <osg/RenderInfo>
@ -50,7 +48,7 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const
if (mWorkQueue) if (mWorkQueue)
mUnrefQueue->flush(mWorkQueue.get()); mUnrefQueue->flush(mWorkQueue.get());
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
if (mImmediateCompileSet.empty() && mCompileSet.empty()) if (mImmediateCompileSet.empty() && mCompileSet.empty())
return; return;
@ -177,7 +175,7 @@ void CompositeMapRenderer::setTargetFrameRate(float framerate)
void CompositeMapRenderer::addCompositeMap(CompositeMap* compositeMap, bool immediate) void CompositeMapRenderer::addCompositeMap(CompositeMap* compositeMap, bool immediate)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
if (immediate) if (immediate)
mImmediateCompileSet.insert(compositeMap); mImmediateCompileSet.insert(compositeMap);
else else
@ -186,7 +184,7 @@ void CompositeMapRenderer::addCompositeMap(CompositeMap* compositeMap, bool imme
void CompositeMapRenderer::setImmediate(CompositeMap* compositeMap) void CompositeMapRenderer::setImmediate(CompositeMap* compositeMap)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
CompileSet::iterator found = mCompileSet.find(compositeMap); CompileSet::iterator found = mCompileSet.find(compositeMap);
if (found == mCompileSet.end()) if (found == mCompileSet.end())
return; return;
@ -199,7 +197,7 @@ void CompositeMapRenderer::setImmediate(CompositeMap* compositeMap)
unsigned int CompositeMapRenderer::getCompileSetSize() const unsigned int CompositeMapRenderer::getCompileSetSize() const
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
return mCompileSet.size(); return mCompileSet.size();
} }

@ -3,9 +3,8 @@
#include <osg/Drawable> #include <osg/Drawable>
#include <OpenThreads/Mutex>
#include <set> #include <set>
#include <mutex>
namespace osg namespace osg
{ {
@ -76,7 +75,7 @@ namespace Terrain
mutable CompileSet mCompileSet; mutable CompileSet mCompileSet;
mutable CompileSet mImmediateCompileSet; mutable CompileSet mImmediateCompileSet;
mutable OpenThreads::Mutex mMutex; mutable std::mutex mMutex;
osg::ref_ptr<osg::FrameBufferObject> mFBO; osg::ref_ptr<osg::FrameBufferObject> mFBO;
}; };

@ -453,7 +453,7 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
void QuadTreeWorld::ensureQuadTreeBuilt() void QuadTreeWorld::ensureQuadTreeBuilt()
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mQuadTreeMutex); std::lock_guard<std::mutex> lock(mQuadTreeMutex);
if (mQuadTreeBuilt) if (mQuadTreeBuilt)
return; return;

@ -4,7 +4,7 @@
#include "world.hpp" #include "world.hpp"
#include "terraingrid.hpp" #include "terraingrid.hpp"
#include <OpenThreads/Mutex> #include <mutex>
namespace osg namespace osg
{ {
@ -61,7 +61,7 @@ namespace Terrain
std::vector<ChunkManager*> mChunkManagers; std::vector<ChunkManager*> mChunkManagers;
OpenThreads::Mutex mQuadTreeMutex; std::mutex mQuadTreeMutex;
bool mQuadTreeBuilt; bool mQuadTreeBuilt;
float mLodFactor; float mLodFactor;
int mVertexLodMod; int mVertexLodMod;

@ -3,6 +3,8 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
#include <thread>
#include <chrono>
#include <osg/Texture2D> #include <osg/Texture2D>
@ -95,14 +97,14 @@ void PacketQueue::put(AVPacket *pkt)
this->last_pkt = pkt1; this->last_pkt = pkt1;
this->nb_packets++; this->nb_packets++;
this->size += pkt1->pkt.size; this->size += pkt1->pkt.size;
this->cond.signal(); this->cond.notify_one();
this->mutex.unlock(); this->mutex.unlock();
} }
int PacketQueue::get(AVPacket *pkt, VideoState *is) int PacketQueue::get(AVPacket *pkt, VideoState *is)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(this->mutex); std::unique_lock<std::mutex> lock(this->mutex);
while(!is->mQuit) while(!is->mQuit)
{ {
AVPacketList *pkt1 = this->first_pkt; AVPacketList *pkt1 = this->first_pkt;
@ -122,7 +124,7 @@ int PacketQueue::get(AVPacket *pkt, VideoState *is)
if(this->flushing) if(this->flushing)
break; break;
this->cond.wait(&this->mutex); this->cond.wait(lock);
} }
return -1; return -1;
@ -131,7 +133,7 @@ int PacketQueue::get(AVPacket *pkt, VideoState *is)
void PacketQueue::flush() void PacketQueue::flush()
{ {
this->flushing = true; this->flushing = true;
this->cond.signal(); this->cond.notify_one();
} }
void PacketQueue::clear() void PacketQueue::clear()
@ -226,7 +228,7 @@ void VideoState::video_display(VideoPicture *vp)
void VideoState::video_refresh() void VideoState::video_refresh()
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(this->pictq_mutex); std::lock_guard<std::mutex> lock(this->pictq_mutex);
if(this->pictq_size == 0) if(this->pictq_size == 0)
return; return;
@ -238,7 +240,7 @@ void VideoState::video_refresh()
this->pictq_rindex = (pictq_rindex+1) % VIDEO_PICTURE_ARRAY_SIZE; this->pictq_rindex = (pictq_rindex+1) % VIDEO_PICTURE_ARRAY_SIZE;
this->frame_last_pts = vp->pts; this->frame_last_pts = vp->pts;
this->pictq_size--; this->pictq_size--;
this->pictq_cond.signal(); this->pictq_cond.notify_one();
} }
else else
{ {
@ -268,7 +270,7 @@ void VideoState::video_refresh()
// update queue for next picture // update queue for next picture
this->pictq_size--; this->pictq_size--;
this->pictq_rindex = (this->pictq_rindex+1) % VIDEO_PICTURE_ARRAY_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 */ /* wait until we have a new pic */
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(this->pictq_mutex); std::unique_lock<std::mutex> lock(this->pictq_mutex);
while(this->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE && !this->mQuit) 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) if(this->mQuit)
return -1; return -1;
@ -340,16 +342,21 @@ double VideoState::synchronize_video(AVFrame *src_frame, double pts)
return pts; return pts;
} }
class VideoThread : public OpenThreads::Thread class VideoThread
{ {
public: public:
VideoThread(VideoState* self) VideoThread(VideoState* self)
: mVideoState(self) : mVideoState(self)
, mThread([this] { run(); })
{ {
start();
} }
virtual void run() ~VideoThread()
{
mThread.join();
}
void run()
{ {
VideoState* self = mVideoState; VideoState* self = mVideoState;
AVPacket pkt1, *packet = &pkt1; AVPacket pkt1, *packet = &pkt1;
@ -408,18 +415,24 @@ public:
private: private:
VideoState* mVideoState; VideoState* mVideoState;
std::thread mThread;
}; };
class ParseThread : public OpenThreads::Thread class ParseThread
{ {
public: public:
ParseThread(VideoState* self) ParseThread(VideoState* self)
: mVideoState(self) : mVideoState(self)
, mThread([this] { run(); })
{
}
~ParseThread()
{ {
start(); mThread.join();
} }
virtual void run() void run()
{ {
VideoState* self = mVideoState; VideoState* self = mVideoState;
@ -503,7 +516,7 @@ public:
if((self->audio_st && self->audioq.size > MAX_AUDIOQ_SIZE) || if((self->audio_st && self->audioq.size > MAX_AUDIOQ_SIZE) ||
(self->video_st && self->videoq.size > MAX_VIDEOQ_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; continue;
} }
@ -534,6 +547,7 @@ public:
private: private:
VideoState* mVideoState; VideoState* mVideoState;
std::thread mThread;
}; };
@ -712,12 +726,10 @@ void VideoState::deinit()
if (this->parse_thread.get()) if (this->parse_thread.get())
{ {
this->parse_thread->join();
this->parse_thread.reset(); this->parse_thread.reset();
} }
if (this->video_thread.get()) if (this->video_thread.get())
{ {
this->video_thread->join();
this->video_thread.reset(); this->video_thread.reset();
} }
@ -816,7 +828,7 @@ ExternalClock::ExternalClock()
void ExternalClock::setPaused(bool paused) void ExternalClock::setPaused(bool paused)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
if (mPaused == paused) if (mPaused == paused)
return; return;
if (paused) if (paused)
@ -830,7 +842,7 @@ void ExternalClock::setPaused(bool paused)
uint64_t ExternalClock::get() uint64_t ExternalClock::get()
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
if (mPaused) if (mPaused)
return mPausedAt; return mPausedAt;
else else
@ -839,7 +851,7 @@ uint64_t ExternalClock::get()
void ExternalClock::set(uint64_t time) void ExternalClock::set(uint64_t time)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
mTimeBase = av_gettime() - time; mTimeBase = av_gettime() - time;
mPausedAt = time; mPausedAt = time;
} }

@ -6,10 +6,8 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <string> #include <string>
#include <mutex>
#include <OpenThreads/Thread> #include <condition_variable>
#include <OpenThreads/Mutex>
#include <OpenThreads/Condition>
#include <osg/ref_ptr> #include <osg/ref_ptr>
namespace osg namespace osg
@ -64,7 +62,7 @@ struct ExternalClock
uint64_t mPausedAt; uint64_t mPausedAt;
bool mPaused; bool mPaused;
OpenThreads::Mutex mMutex; std::mutex mMutex;
void setPaused(bool paused); void setPaused(bool paused);
uint64_t get(); uint64_t get();
@ -83,8 +81,8 @@ struct PacketQueue {
std::atomic<int> nb_packets; std::atomic<int> nb_packets;
std::atomic<int> size; std::atomic<int> size;
OpenThreads::Mutex mutex; std::mutex mutex;
OpenThreads::Condition cond; std::condition_variable cond;
void put(AVPacket *pkt); void put(AVPacket *pkt);
int get(AVPacket *pkt, VideoState *is); int get(AVPacket *pkt, VideoState *is);
@ -164,8 +162,8 @@ struct VideoState {
VideoPicture pictq[VIDEO_PICTURE_ARRAY_SIZE]; VideoPicture pictq[VIDEO_PICTURE_ARRAY_SIZE];
AVFrame* rgbaFrame; // used as buffer for the frame converted from its native format to RGBA AVFrame* rgbaFrame; // used as buffer for the frame converted from its native format to RGBA
int pictq_size, pictq_rindex, pictq_windex; int pictq_size, pictq_rindex, pictq_windex;
OpenThreads::Mutex pictq_mutex; std::mutex pictq_mutex;
OpenThreads::Condition pictq_cond; std::condition_variable pictq_cond;
std::unique_ptr<ParseThread> parse_thread; std::unique_ptr<ParseThread> parse_thread;
std::unique_ptr<VideoThread> video_thread; std::unique_ptr<VideoThread> video_thread;

Loading…
Cancel
Save