From 6be19284479d9169ef169a749888c7cc2e109fa5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 14 May 2008 13:16:36 +0000 Subject: [PATCH] Introduced a thread safe map which manages a single EasyCurl object per thread. --- src/osgPlugins/curl/ReaderWriterCURL.cpp | 31 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/curl/ReaderWriterCURL.cpp b/src/osgPlugins/curl/ReaderWriterCURL.cpp index ff2984bf6..afcf65817 100644 --- a/src/osgPlugins/curl/ReaderWriterCURL.cpp +++ b/src/osgPlugins/curl/ReaderWriterCURL.cpp @@ -22,7 +22,7 @@ #include #include -class EasyCurl +class EasyCurl : public osg::Referenced { public: @@ -50,6 +50,8 @@ class EasyCurl EasyCurl() { + osg::notify(osg::INFO)<<"EasyCurl::EasyCurl()"< > ThreadCurlMap; - mutable EasyCurl _easyCurl; + EasyCurl& getEasyCurl() const + { + OpenThreads::ScopedLock lock(_threadCurlMapMutex); + + osg::ref_ptr& ec = _threadCurlMap[OpenThreads::Thread::CurrentThread()]; + if (!ec) ec = new EasyCurl; + + return *ec; + } + + mutable OpenThreads::Mutex _threadCurlMapMutex; + mutable ThreadCurlMap _threadCurlMap; };