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
${OSG_LIBRARIES}
${OPENTHREADS_LIBRARIES}
${OSGTEXT_LIBRARIES}
${OSGUTIL_LIBRARIES}
${OSGVIEWER_LIBRARIES}

@ -1,5 +1,8 @@
#include "scenewidget.hpp"
#include <chrono>
#include <thread>
#include <QEvent>
#include <QResizeEvent>
#include <QTimer>
@ -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<double>(minFrameTime - dt));
}
}

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

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

@ -1,8 +1,8 @@
#include "environment.hpp"
#include <cassert>
#include <OpenThreads/Thread>
#include <chrono>
#include <thread>
#include "world.hpp"
#include "scriptmanager.hpp"
@ -99,7 +99,7 @@ void MWBase::Environment::limitFrameRate(double dt) const
double minFrameTime = 1.0 / static_cast<double>(mFrameRateLimit);
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 <cassert>
#include <chrono>
#include <thread>
#include <osgViewer/Viewer>
@ -751,7 +753,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();
@ -1788,7 +1790,7 @@ namespace MWGui
if (!mWindowVisible)
{
mVideoWidget->pause();
OpenThreads::Thread::microSleep(5000);
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}
else
{

@ -428,7 +428,7 @@ namespace MWRender
if (activeGrid)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mRefTrackerMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(mSizeCacheMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(mRefTrackerMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(mSizeCacheMutex);
std::lock_guard<std::mutex> lock(mSizeCacheMutex);
mSizeCache[pair.first] = radius2;
continue;
}
@ -685,7 +685,7 @@ namespace MWRender
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.insert(refnum).second) return false;
if (mRefTrackerLocked) return false;
@ -706,7 +706,7 @@ namespace MWRender
return false;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mRefTrackerMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(mRefTrackerMutex);
std::lock_guard<std::mutex> lock(mRefTrackerMutex);
mRefTrackerNew.mDisabled.clear();
mRefTrackerNew.mBlacklist.clear();
mRefTrackerLocked = true;
@ -734,7 +734,7 @@ namespace MWRender
{
if (!mRefTrackerLocked) return false;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mRefTrackerMutex);
std::lock_guard<std::mutex> lock(mRefTrackerMutex);
mRefTrackerLocked = false;
if (mRefTracker == mRefTrackerNew)
return false;

@ -5,7 +5,7 @@
#include <components/resource/resourcemanager.hpp>
#include <components/esm/loadcell.hpp>
#include <OpenThreads/Mutex>
#include <mutex>
namespace Resource
{
@ -58,7 +58,7 @@ namespace MWRender
float mMinSizeMergeFactor;
float mMinSizeCostMultiplier;
OpenThreads::Mutex mRefTrackerMutex;
std::mutex mRefTrackerMutex;
struct RefTracker
{
std::set<ESM::RefNum> 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<ESM::RefNum, float> SizeCache;
SizeCache mSizeCache;
};

@ -2,6 +2,8 @@
#include <limits>
#include <cstdlib>
#include <condition_variable>
#include <mutex>
#include <osg/Light>
#include <osg/LightModel>
@ -709,24 +711,24 @@ namespace MWRender
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)
{
mDone = true;
mCondition.signal();
mCondition.notify_one();
}
}
void waitTillDone()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
std::unique_lock<std::mutex> 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;
};

@ -4,6 +4,10 @@
#include <memory>
#include <array>
#include <atomic>
#include <condition_variable>
#include <thread>
#include <mutex>
#include <chrono>
#include <stdint.h>
@ -11,11 +15,6 @@
#include <components/misc/constants.hpp>
#include <components/vfs/manager.hpp>
#include <OpenThreads/Thread>
#include <OpenThreads/Condition>
#include <OpenThreads/Mutex>
#include <OpenThreads/ScopedLock>
#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<OpenAL_SoundStream*> StreamVec;
StreamVec mStreams;
std::atomic<bool> 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<OpenThreads::Mutex> lock(mMutex);
std::unique_lock<std::mutex> 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<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
StreamVec::iterator iter = std::find(mStreams.begin(), mStreams.end(), stream);
if(iter != mStreams.end()) mStreams.erase(iter);
}
void removeAll()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> 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<OpenAL_SoundStream*>(sound->mHandle);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mStreamThread->mMutex);
std::lock_guard<std::mutex> 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<OpenAL_SoundStream*>(sound->mHandle);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mStreamThread->mMutex);
std::lock_guard<std::mutex> 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<OpenAL_SoundStream*>(sound->mHandle);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mStreamThread->mMutex);
std::lock_guard<std::mutex> lock(mStreamThread->mMutex);
return stream->isPlaying();
}

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

@ -2,8 +2,6 @@
#include <set>
#include <OpenThreads/ScopedLock>
#include <osg/Image>
#include <osg/Plane>
@ -548,7 +546,7 @@ namespace ESMTerrain
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?
std::map<std::string, Terrain::LayerInfo>::iterator found = mLayerInfoMap.find(texture);

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

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

@ -21,7 +21,7 @@ namespace Resource
{
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
ObjectCacheMap::iterator oitr = _objectCache.begin();
@ -45,7 +45,7 @@ namespace Resource
void MultiObjectCache::clear()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(_objectCacheMutex);
std::lock_guard<std::mutex> lock(_objectCacheMutex);
_objectCache.insert(std::make_pair(filename, object));
}
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);
if (found == _objectCache.end())
return osg::ref_ptr<osg::Object>();
@ -76,7 +76,7 @@ namespace Resource
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();
itr != _objectCache.end();
@ -89,7 +89,7 @@ namespace Resource
unsigned int MultiObjectCache::getCacheSize() const
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
std::lock_guard<std::mutex> lock(_objectCacheMutex);
return _objectCache.size();
}

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

@ -26,6 +26,7 @@
#include <string>
#include <map>
#include <mutex>
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<OpenThreads::Mutex> lock(_objectCacheMutex);
std::lock_guard<std::mutex> 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<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
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<OpenThreads::Mutex> lock(_objectCacheMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(_objectCacheMutex);
std::lock_guard<std::mutex> lock(_objectCacheMutex);
_objectCache[key]=ObjectTimeStampPair(object,timestamp);
}
/** Remove Object from cache.*/
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);
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*/
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);
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<OpenThreads::Mutex> lock(_objectCacheMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(_objectCacheMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(_objectCacheMutex);
std::lock_guard<std::mutex> 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 <class Functor>
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)
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<OpenThreads::Mutex> lock(_objectCacheMutex);
std::lock_guard<std::mutex> lock(_objectCacheMutex);
return _objectCache.size();
}
@ -185,7 +186,7 @@ class GenericObjectCache : public osg::Referenced
typedef std::map<KeyType, ObjectTimeStampPair > ObjectCacheMap;
ObjectCacheMap _objectCache;
mutable OpenThreads::Mutex _objectCacheMutex;
mutable std::mutex _objectCacheMutex;
};

@ -126,7 +126,7 @@ namespace Resource
void clearCache()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_listMutex);
std::lock_guard<OpenThreads::Mutex> lock(_listMutex);
_sharedTextureList.clear();
_sharedStateSetList.clear();
}
@ -625,7 +625,7 @@ namespace Resource
mShaderManager->releaseGLObjects(state);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mSharedStateMutex);
std::lock_guard<std::mutex> lock(mSharedStateMutex);
mSharedStateManager->releaseGLObjects(state);
}
@ -717,7 +717,7 @@ namespace Resource
if (mIncrementalCompileOperation)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*mIncrementalCompileOperation->getToCompiledMutex());
std::lock_guard<OpenThreads::Mutex> 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<OpenThreads::Mutex> lock(mSharedStateMutex);
std::lock_guard<std::mutex> lock(mSharedStateMutex);
mSharedStateManager->clearCache();
mInstanceCache->clear();
}
@ -747,12 +747,12 @@ namespace Resource
{
if (mIncrementalCompileOperation)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*mIncrementalCompileOperation->getToCompiledMutex());
std::lock_guard<OpenThreads::Mutex> lock(*mIncrementalCompileOperation->getToCompiledMutex());
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, "StateSet", mSharedStateManager->getNumSharedStateSets());
}

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

@ -891,7 +891,7 @@ MWShadowTechnique::ViewDependentData* MWShadowTechnique::createViewDependentData
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);
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<osg::Uniform> validRegionUniform;
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_accessUniformsAndProgramMutex);
std::lock_guard<std::mutex> lock(_accessUniformsAndProgramMutex);
for (auto uniform : _uniforms)
{
@ -1467,7 +1467,7 @@ void MWShadowTechnique::createShaders()
unsigned int _baseTextureUnit = 0;
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_accessUniformsAndProgramMutex);
std::lock_guard<std::mutex> lock(_accessUniformsAndProgramMutex);
_shadowCastingStateSet = new osg::StateSet;
@ -2980,7 +2980,7 @@ osg::StateSet* MWShadowTechnique::selectStateSetForRenderingShadow(ViewDependent
osg::ref_ptr<osg::StateSet> stateset = vdd.getStateSet();
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_accessUniformsAndProgramMutex);
std::lock_guard<std::mutex> lock(_accessUniformsAndProgramMutex);
vdd.getStateSet()->clear();
@ -3057,7 +3057,7 @@ void MWShadowTechnique::resizeGLObjectBuffers(unsigned int /*maxSize*/)
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();
itr != _viewDependentDataMap.end();
++itr)

@ -19,6 +19,8 @@
#ifndef COMPONENTS_SCENEUTIL_MWSHADOWTECHNIQUE_H
#define COMPONENTS_SCENEUTIL_MWSHADOWTECHNIQUE_H 1
#include <mutex>
#include <osg/Camera>
#include <osg/Material>
#include <osg/MatrixTransform>
@ -234,7 +236,7 @@ namespace SceneUtil {
virtual ~MWShadowTechnique();
typedef std::map< osgUtil::CullVisitor*, osg::ref_ptr<ViewDependentData> > ViewDependentDataMap;
mutable OpenThreads::Mutex _viewDependentDataMapMutex;
mutable std::mutex _viewDependentDataMapMutex;
ViewDependentDataMap _viewDependentDataMap;
osg::ref_ptr<osg::StateSet> _shadowRecievingPlaceholderStateSet;
@ -245,7 +247,7 @@ namespace SceneUtil {
osg::ref_ptr<osg::Texture2D> _fallbackShadowMapTexture;
typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms;
mutable OpenThreads::Mutex _accessUniformsAndProgramMutex;
mutable std::mutex _accessUniformsAndProgramMutex;
Uniforms _uniforms;
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)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> 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<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));
if (found == mPrograms.end())
{
@ -362,7 +362,7 @@ namespace Shader
void ShaderManager::releaseGLObjects(osg::State *state)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
for (auto shader : mShaders)
{
if (shader.second != nullptr)

@ -3,6 +3,7 @@
#include <string>
#include <map>
#include <mutex>
#include <osg/ref_ptr>
@ -10,8 +11,6 @@
#include <osgViewer/Viewer>
#include <OpenThreads/Mutex>
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;
ProgramMap mPrograms;
OpenThreads::Mutex mMutex;
std::mutex mMutex;
const osg::ref_ptr<osg::Uniform> mShadowMapAlphaTestEnableUniform = new osg::Uniform();
const osg::ref_ptr<osg::Uniform> mShadowMapAlphaTestDisableUniform = new osg::Uniform();

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

@ -6,6 +6,7 @@
#include <osg/PrimitiveSet>
#include <map>
#include <mutex>
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<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;
OpenThreads::Mutex mUvBufferMutex;
std::mutex mUvBufferMutex;
};
}

@ -1,7 +1,5 @@
#include "compositemaprenderer.hpp"
#include <OpenThreads/ScopedLock>
#include <osg/FrameBufferObject>
#include <osg/Texture2D>
#include <osg/RenderInfo>
@ -50,7 +48,7 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const
if (mWorkQueue)
mUnrefQueue->flush(mWorkQueue.get());
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> 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<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
return mCompileSet.size();
}

@ -3,9 +3,8 @@
#include <osg/Drawable>
#include <OpenThreads/Mutex>
#include <set>
#include <mutex>
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<osg::FrameBufferObject> mFBO;
};

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

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

@ -3,6 +3,8 @@
#include <algorithm>
#include <cassert>
#include <iostream>
#include <thread>
#include <chrono>
#include <osg/Texture2D>
@ -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<OpenThreads::Mutex> lock(this->mutex);
std::unique_lock<std::mutex> 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<OpenThreads::Mutex> lock(this->pictq_mutex);
std::lock_guard<std::mutex> 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<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)
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<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
if (mPaused == paused)
return;
if (paused)
@ -830,7 +842,7 @@ void ExternalClock::setPaused(bool paused)
uint64_t ExternalClock::get()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
if (mPaused)
return mPausedAt;
else
@ -839,7 +851,7 @@ uint64_t ExternalClock::get()
void ExternalClock::set(uint64_t time)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
mTimeBase = av_gettime() - time;
mPausedAt = time;
}

@ -6,10 +6,8 @@
#include <vector>
#include <memory>
#include <string>
#include <OpenThreads/Thread>
#include <OpenThreads/Mutex>
#include <OpenThreads/Condition>
#include <mutex>
#include <condition_variable>
#include <osg/ref_ptr>
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<int> nb_packets;
std::atomic<int> 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<ParseThread> parse_thread;
std::unique_ptr<VideoThread> video_thread;

Loading…
Cancel
Save