浏览代码

Replaced boost::thread with std::thread

mensinda 9 年之前
父节点
当前提交
4836a2993e
共有 3 个文件被更改,包括 23 次插入37 次删除
  1. 11 11
      code/Assimp.cpp
  2. 8 7
      code/DefaultLogger.cpp
  3. 4 19
      include/assimp/defs.h

+ 11 - 11
code/Assimp.cpp

@@ -59,8 +59,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 // ------------------------------------------------------------------------------------------------
 #ifndef ASSIMP_BUILD_SINGLETHREADED
-#   include <boost/thread/thread.hpp>
-#   include <boost/thread/mutex.hpp>
+#   include <thread>
+#   include <mutex>
 #endif
 // ------------------------------------------------------------------------------------------------
 using namespace Assimp;
@@ -103,7 +103,7 @@ namespace Assimp
 
 #ifndef ASSIMP_BUILD_SINGLETHREADED
 /** Global mutex to manage the access to the log-stream map */
-static boost::mutex gLogStreamMutex;
+static std::mutex gLogStreamMutex;
 #endif
 
 
@@ -119,7 +119,7 @@ public:
 
     ~LogToCallbackRedirector()  {
 #ifndef ASSIMP_BUILD_SINGLETHREADED
-        boost::mutex::scoped_lock lock(gLogStreamMutex);
+        std::lock_guard<std::mutex> lock(gLogStreamMutex);
 #endif
         // (HACK) Check whether the 'stream.user' pointer points to a
         // custom LogStream allocated by #aiGetPredefinedLogStream.
@@ -321,8 +321,8 @@ ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
 }
 
 // ------------------------------------------------------------------------------------------------
-ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing( const aiScene *scene, 
-                                                           BaseProcess* process, 
+ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing( const aiScene *scene,
+                                                           BaseProcess* process,
                                                            bool requestValidation ) {
     const aiScene* sc( NULL );
 
@@ -343,7 +343,7 @@ ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing( const aiScene *scene,
     }
 
     ASSIMP_END_EXCEPTION_REGION( const aiScene* );
-    
+
     return sc;
 }
 
@@ -383,7 +383,7 @@ ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
     ASSIMP_BEGIN_EXCEPTION_REGION();
 
 #ifndef ASSIMP_BUILD_SINGLETHREADED
-    boost::mutex::scoped_lock lock(gLogStreamMutex);
+    std::lock_guard<std::mutex> lock(gLogStreamMutex);
 #endif
 
     LogStream* lg = new LogToCallbackRedirector(*stream);
@@ -402,7 +402,7 @@ ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
     ASSIMP_BEGIN_EXCEPTION_REGION();
 
 #ifndef ASSIMP_BUILD_SINGLETHREADED
-    boost::mutex::scoped_lock lock(gLogStreamMutex);
+    std::lock_guard<std::mutex> lock(gLogStreamMutex);
 #endif
     // find the log-stream associated with this data
     LogStreamMap::iterator it = gActiveLogStreams.find( *stream);
@@ -427,7 +427,7 @@ ASSIMP_API void aiDetachAllLogStreams(void)
 {
     ASSIMP_BEGIN_EXCEPTION_REGION();
 #ifndef ASSIMP_BUILD_SINGLETHREADED
-    boost::mutex::scoped_lock lock(gLogStreamMutex);
+    std::lock_guard<std::mutex> lock(gLogStreamMutex);
 #endif
     Logger *logger( DefaultLogger::get() );
     if ( NULL == logger ) {
@@ -440,7 +440,7 @@ ASSIMP_API void aiDetachAllLogStreams(void)
     }
     gActiveLogStreams.clear();
     DefaultLogger::kill();
-    
+
     ASSIMP_END_EXCEPTION_REGION(void);
 }
 

+ 8 - 7
code/DefaultLogger.cpp

@@ -57,10 +57,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <stdio.h>
 
 #ifndef ASSIMP_BUILD_SINGLETHREADED
-#   include <boost/thread/thread.hpp>
-#   include <boost/thread/mutex.hpp>
+#   include <thread>
+#   include <mutex>
 
-boost::mutex loggerMutex;
+std::mutex loggerMutex;
 #endif
 
 namespace Assimp    {
@@ -135,7 +135,7 @@ Logger *DefaultLogger::create(const char* name /*= "AssimpLog.txt"*/,
 {
     // enter the mutex here to avoid concurrency problems
 #ifndef ASSIMP_BUILD_SINGLETHREADED
-    boost::mutex::scoped_lock lock(loggerMutex);
+    std::lock_guard<std::mutex> lock(loggerMutex);
 #endif
 
     if (m_pLogger && !isNullLogger() )
@@ -210,7 +210,7 @@ void DefaultLogger::set( Logger *logger )
 {
     // enter the mutex here to avoid concurrency problems
 #ifndef ASSIMP_BUILD_SINGLETHREADED
-    boost::mutex::scoped_lock lock(loggerMutex);
+    std::lock_guard<std::mutex> lock(loggerMutex);
 #endif
 
     if (!logger)logger = &s_pNullLogger;
@@ -237,7 +237,7 @@ void DefaultLogger::kill()
 {
     // enter the mutex here to avoid concurrency problems
 #ifndef ASSIMP_BUILD_SINGLETHREADED
-    boost::mutex::scoped_lock lock(loggerMutex);
+    std::lock_guard<std::mutex> lock(loggerMutex);
 #endif
 
 	if ( m_pLogger == &s_pNullLogger ) {
@@ -413,7 +413,8 @@ void DefaultLogger::WriteToStreams(const char *message, ErrorSeverity ErrorSev )
 //  Returns thread id, if not supported only a zero will be returned.
 unsigned int DefaultLogger::GetThreadID()
 {
-    // fixme: we can get this value via boost::threads
+    // fixme: we can get this value via std::threads
+    // std::this_thread::get_id().hash() returns a (big) size_t, not sure if this is useful in this case.
 #ifdef WIN32
     return (unsigned int)::GetCurrentThreadId();
 #else

+ 4 - 19
include/assimp/defs.h

@@ -212,31 +212,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // "W8059 Packgr��e der Struktur ge�ndert"
 
 #endif
-    //////////////////////////////////////////////////////////////////////////
-    /* Define 'ASSIMP_BUILD_BOOST_WORKAROUND' to compile assimp
-     * without boost. This is done by using a few workaround
-     * classes and brings some limitations (e.g. some logging won't be done,
-     * the library won't utilize threads or be threadsafe at all).
-     * This implies the 'ASSIMP_BUILD_SINGLETHREADED' setting. */
-     //////////////////////////////////////////////////////////////////////////
-#ifdef ASSIMP_BUILD_BOOST_WORKAROUND
 
-    // threading support requires boost
-#ifndef ASSIMP_BUILD_SINGLETHREADED
-#   define ASSIMP_BUILD_SINGLETHREADED
-#endif
-
-#endif // !! ASSIMP_BUILD_BOOST_WORKAROUND
 
     //////////////////////////////////////////////////////////////////////////
     /* Define ASSIMP_BUILD_SINGLETHREADED to compile assimp
      * without threading support. The library doesn't utilize
-     * threads then and is itself not threadsafe.
-     * If this flag is specified boost::threads is *not* required. */
+     * threads then and is itself not threadsafe. */
     //////////////////////////////////////////////////////////////////////////
-#ifndef ASSIMP_BUILD_SINGLETHREADED
-#   define ASSIMP_BUILD_SINGLETHREADED
-#endif
+// #ifndef ASSIMP_BUILD_SINGLETHREADED
+// #   define ASSIMP_BUILD_SINGLETHREADED
+// #endif
 
 #if defined(_DEBUG) || ! defined(NDEBUG)
 #   define ASSIMP_BUILD_DEBUG