2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit c488b267 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Introducing C++11 support switch for <thread> and <condition_variable>.

If you need one of these two C++11 headers, include <ext/threading.h> instead, which will use C++11 headers if present or TBB's compatibility layer otherwise.

closes #567
parent b4547688
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "tgt/texturereadertga.h" #include "tgt/texturereadertga.h"
#include "tgt/qt/qtapplication.h" #include "tgt/qt/qtapplication.h"
#include "tgt/qt/qtthreadedcanvas.h" #include "tgt/qt/qtthreadedcanvas.h"
#include "tbb/compat/thread"
#include "application/campvispainter.h" #include "application/campvispainter.h"
#include "application/gui/mainwindow.h" #include "application/gui/mainwindow.h"
...@@ -44,6 +43,7 @@ ...@@ -44,6 +43,7 @@
#include "core/tools/quadrenderer.h" #include "core/tools/quadrenderer.h"
#include "core/pipeline/abstractpipeline.h" #include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/visualizationprocessor.h" #include "core/pipeline/visualizationprocessor.h"
#include "modules/pipelinefactory.h" #include "modules/pipelinefactory.h"
#ifdef CAMPVIS_HAS_SCRIPTING #ifdef CAMPVIS_HAS_SCRIPTING
......
...@@ -26,8 +26,9 @@ ...@@ -26,8 +26,9 @@
#define CAMPVISPAINTER_H__ #define CAMPVISPAINTER_H__
#include "sigslot/sigslot.h" #include "sigslot/sigslot.h"
#include "tbb/atomic.h"
#include "tbb/compat/condition_variable" #include <ext/threading.h>
#include <tbb/atomic.h>
#include "tgt/logmanager.h" #include "tgt/logmanager.h"
#include "tgt/painter.h" #include "tgt/painter.h"
......
...@@ -156,8 +156,6 @@ ENDIF(WIN32) ...@@ -156,8 +156,6 @@ ENDIF(WIN32)
IF(CMAKE_COMPILER_IS_GNUCXX) IF(CMAKE_COMPILER_IS_GNUCXX)
# enable C++11 support in GCC # enable C++11 support in GCC
LIST(APPEND CMAKE_CXX_FLAGS "-std=c++11") LIST(APPEND CMAKE_CXX_FLAGS "-std=c++11")
# however: we want to use the TBB implementation of threads
LIST(APPEND CampvisGlobalDefinitions "-DTBB_IMPLEMENT_CPP0X")
ENDIF() ENDIF()
# tgt configuration # tgt configuration
......
...@@ -22,9 +22,10 @@ ...@@ -22,9 +22,10 @@
// //
// ================================================================================================ // ================================================================================================
#include <tbb/compat/thread>
#include "tgt/assert.h" #include "tgt/assert.h"
#include <ext/threading.h>
#include "abstractprocessor.h" #include "abstractprocessor.h"
#include "core/properties/abstractproperty.h" #include "core/properties/abstractproperty.h"
#include "core/tools/job.h" #include "core/tools/job.h"
......
...@@ -81,7 +81,7 @@ namespace campvis { ...@@ -81,7 +81,7 @@ namespace campvis {
void OpenGLJobProcessor::run() { void OpenGLJobProcessor::run() {
_this_thread_id = std::this_thread::get_id(); _this_thread_id = std::this_thread::get_id();
std::unique_lock<tbb::mutex> lock(tgt::GlContextManager::getRef().getGlMutex()); std::unique_lock<std::mutex> lock(tgt::GlContextManager::getRef().getGlMutex());
clock_t lastCleanupTime = clock() * 1000 / CLOCKS_PER_SEC; clock_t lastCleanupTime = clock() * 1000 / CLOCKS_PER_SEC;
while (! _stopExecution) { while (! _stopExecution) {
......
...@@ -27,14 +27,15 @@ ...@@ -27,14 +27,15 @@
#include "sigslot/sigslot.h" #include "sigslot/sigslot.h"
#include "tgt/glcontextmanager.h" #include <ext/threading.h>
#include "tgt/singleton.h"
#include <tbb/atomic.h> #include <tbb/atomic.h>
#include <tbb/concurrent_queue.h> #include <tbb/concurrent_queue.h>
#include <tbb/concurrent_hash_map.h> #include <tbb/concurrent_hash_map.h>
#include <tbb/concurrent_vector.h> #include <tbb/concurrent_vector.h>
#include <tbb/compat/condition_variable>
#include "tgt/glcontextmanager.h"
#include "tgt/singleton.h"
#include "core/coreapi.h" #include "core/coreapi.h"
#include "core/tools/job.h" #include "core/tools/job.h"
......
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
#define RUNNABLE_H__ #define RUNNABLE_H__
#include "tgt/logmanager.h" #include "tgt/logmanager.h"
#include <tbb/compat/thread>
#include <ext/threading.h>
#include <tbb/atomic.h> #include <tbb/atomic.h>
#include "core/coreapi.h" #include "core/coreapi.h"
......
...@@ -25,7 +25,7 @@ namespace tgt { ...@@ -25,7 +25,7 @@ namespace tgt {
_glMutex.unlock(); _glMutex.unlock();
} }
tbb::mutex& GlContextManager::getGlMutex() { std::mutex& GlContextManager::getGlMutex() {
return _glMutex; return _glMutex;
} }
...@@ -58,7 +58,7 @@ namespace tgt { ...@@ -58,7 +58,7 @@ namespace tgt {
tgtAssert(_contexts.find(context) == _contexts.end(), "Tried to double register the same context."); tgtAssert(_contexts.find(context) == _contexts.end(), "Tried to double register the same context.");
{ {
tbb::mutex::scoped_lock localLock(_localMutex); std::lock_guard<std::mutex> localLock(_localMutex);
_contexts.insert(context); _contexts.insert(context);
} }
...@@ -78,7 +78,7 @@ namespace tgt { ...@@ -78,7 +78,7 @@ namespace tgt {
void GlContextManager::removeContext(GLCanvas* context) { void GlContextManager::removeContext(GLCanvas* context) {
_currentContext = 0; _currentContext = 0;
tbb::mutex::scoped_lock lock(_localMutex); std::lock_guard<std::mutex> lock(_localMutex);
std::set<GLCanvas*>::iterator it = _contexts.find(context); std::set<GLCanvas*>::iterator it = _contexts.find(context);
if (it != _contexts.end()) { if (it != _contexts.end()) {
_contexts.erase(it); _contexts.erase(it);
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "tgt/singleton.h" #include "tgt/singleton.h"
#include "tgt/glcanvas.h" #include "tgt/glcanvas.h"
#include "tgt/types.h" #include "tgt/types.h"
#include <tbb/mutex.h> // TODO: TBB dependency in TGT is not that beautiful...
#include <ext/threading.h>
#include <set> #include <set>
#include <string> #include <string>
...@@ -49,7 +50,7 @@ namespace tgt { ...@@ -49,7 +50,7 @@ namespace tgt {
* Returns the mutex protecting the OpenGL context * Returns the mutex protecting the OpenGL context
* \return _glMutex * \return _glMutex
*/ */
tbb::mutex& getGlMutex(); std::mutex& getGlMutex();
/** /**
* Acquires \a context as current OpenGL context. * Acquires \a context as current OpenGL context.
...@@ -97,9 +98,9 @@ namespace tgt { ...@@ -97,9 +98,9 @@ namespace tgt {
std::set<GLCanvas*> _contexts; ///< Map of all OpenGL contexts std::set<GLCanvas*> _contexts; ///< Map of all OpenGL contexts
GLCanvas* _currentContext; ///< Current active OpenGL context GLCanvas* _currentContext; ///< Current active OpenGL context
tbb::mutex _glMutex; ///< Mutex protecting OpenGL for multi-threaded access std::mutex _glMutex; ///< Mutex protecting OpenGL for multi-threaded access
tbb::mutex _localMutex; ///< local mutex to prodect _contexts std::mutex _localMutex; ///< local mutex to prodect _contexts
}; };
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef THREADING_H__
#define THREADING_H__
// This header provides cross-compiler includes for <thread> and <condition_variable>.
// These two includes are defined by C++11 and supported by GCC and MSVC11+. All other
// implementations must use TBBs compat layer implementation.
#if (_MSC_VER == 1600) //check for MSVC2010
#ifndef TBB_IMPLEMENT_CPP0X
#define TBB_IMPLEMENT_CPP0X 1
#endif
#include <tbb/compat/condition_variable>
#include <tbb/compat/thread>
#include <tbb/mutex.h>
namespace std {
// it gets even uglier:
// A C++11 std::condition_variable requires a std::mutex, which however is not provided
// by TBB's compat layer. Hence, we use a tbb::mutex and redeclare it as std::mutex.
using tbb::mutex;
}
#else
#include <condition_variable>
#include <mutex>
#include <thread>
#endif
#endif // THREADING_H__
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include <tgt/matrix.h> #include <tgt/matrix.h>
#include <tbb/compat/thread> #include <ext/threading.h>
#include <tbb/atomic.h> #include <tbb/atomic.h>
#include <tbb/mutex.h> #include <tbb/mutex.h>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment