From 9bd5619750246d5835183619ff8a401f17fd58c8 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sat, 13 Aug 2011 20:41:19 -0400 Subject: [PATCH] linux compilation fixes for GCC 4.5 --- build/config-linux-debug.py | 4 ++-- build/config-linux.py | 4 ++-- include/mitsuba/core/platform.h | 6 ++++++ include/mitsuba/core/thread.h | 17 +++++++++-------- src/libcore/thread.cpp | 31 +++++++++++++++++-------------- src/mtspy/base.cpp | 4 ++++ src/shapes/SConscript | 2 +- src/shapes/ply/ply.cpp | 10 ---------- src/shapes/ply/ply/ply_parser.hpp | 19 ++++++++++++------- 9 files changed, 53 insertions(+), 44 deletions(-) diff --git a/build/config-linux-debug.py b/build/config-linux-debug.py index 48b328e6..c8f9c9ba 100644 --- a/build/config-linux-debug.py +++ b/build/config-linux-debug.py @@ -1,7 +1,7 @@ BUILDDIR = '#build/debug' DISTDIR = '#dist' -CXX = 'g++' -CC = 'gcc' +CXX = 'g++-4.5' +CC = 'gcc-4.5' CXXFLAGS = ['-O0', '-Wall', '-g', '-pipe', '-march=nocona', '-msse2', '-ftree-vectorize', '-mfpmath=sse', '-funsafe-math-optimizations', '-fno-rounding-math', '-fno-signaling-nans', '-fomit-frame-pointer', '-DMTS_DEBUG', '-DSINGLE_PRECISION', '-DSPECTRUM_SAMPLES=3', '-DMTS_SSE', '-DMTS_HAS_COHERENT_RT', '-fopenmp'] LINKFLAGS = [] SHLINKFLAGS = ['-rdynamic', '-shared', '-fPIC'] diff --git a/build/config-linux.py b/build/config-linux.py index 65bebf04..afc6cda3 100644 --- a/build/config-linux.py +++ b/build/config-linux.py @@ -1,7 +1,7 @@ BUILDDIR = '#build/release' DISTDIR = '#dist' -CXX = 'g++' -CC = 'gcc' +CXX = 'g++-4.5' +CC = 'gcc-4.5' CXXFLAGS = ['-O3', '-Wall', '-g', '-pipe', '-march=nocona', '-msse2', '-ftree-vectorize', '-mfpmath=sse', '-funsafe-math-optimizations', '-fno-rounding-math', '-fno-signaling-nans', '-fomit-frame-pointer', '-DMTS_DEBUG', '-DSINGLE_PRECISION', '-DSPECTRUM_SAMPLES=3', '-DMTS_SSE', '-DMTS_HAS_COHERENT_RT', '-fopenmp'] LINKFLAGS = [] SHLINKFLAGS = ['-rdynamic', '-shared', '-fPIC'] diff --git a/include/mitsuba/core/platform.h b/include/mitsuba/core/platform.h index d604a1b5..e3bcca73 100644 --- a/include/mitsuba/core/platform.h +++ b/include/mitsuba/core/platform.h @@ -130,6 +130,12 @@ /* Compile with Boost filesystem v2 */ #define BOOST_FILESYSTEM_VERSION 2 +/* Use ELF support for thread-local storage on Linux? This + * is potentially faster but causes problems when dynamically + * loading Mitsuba from Python, so let's keep it disabled for now + */ +#define MTS_USE_ELF_TLS 0 + #include MTS_NAMESPACE_BEGIN diff --git a/include/mitsuba/core/thread.h b/include/mitsuba/core/thread.h index f204fb0b..7e066a1d 100644 --- a/include/mitsuba/core/thread.h +++ b/include/mitsuba/core/thread.h @@ -80,12 +80,12 @@ public: inline int getStackSize() const { return m_stackSize; } /// Return the thread ID -#if defined(__OSX__) - inline static int getID() { return getThread()->m_id; } -#elif defined(WIN32) +#if defined(WIN32) inline static int getID() { return (int) GetCurrentThreadId(); } -#else +#elif MTS_USE_ELF_TLS == 1 inline static int getID() { return m_id; } +#else + inline static int getID() { return getThread()->m_id; } #endif /// Return the name of this thread @@ -184,11 +184,12 @@ private: #if defined(__LINUX__) || defined(__OSX__) static int m_idCounter; static ref m_idMutex; -#endif -#if defined(__OSX__) +#if MTS_USE_ELF_TLS == 1 + static __thread int m_id + __attribute__((tls_model("global-dynamic"))); +#else int m_id; -#elif defined(__LINUX__) - static int __thread m_id; +#endif #endif }; diff --git a/src/libcore/thread.cpp b/src/libcore/thread.cpp index 427bf83d..a1a5037f 100644 --- a/src/libcore/thread.cpp +++ b/src/libcore/thread.cpp @@ -62,8 +62,9 @@ int Thread::m_idCounter; ref Thread::m_idMutex; #endif -#if defined(__LINUX__) -int __thread __attribute__((tls_model("initial-exec"))) Thread::m_id; +#if MTS_USE_ELF_TLS == 1 +__thread int Thread::m_id + __attribute__((tls_model("global-dynamic"))); #endif Thread::Thread(const std::string &name, unsigned int stackSize) @@ -72,7 +73,7 @@ Thread::Thread(const std::string &name, unsigned int stackSize) m_joinMutex = new Mutex(); memset(&m_thread, 0, sizeof(pthread_t)); } - + void Thread::start() { if (m_running) Log(EError, "Thread is already running!"); @@ -155,14 +156,14 @@ void *Thread::dispatch(void *par) { if (thread->getPriority() != ENormalPriority) thread->setPriority(thread->getPriority()); -#if defined(__OSX__) - m_idMutex->lock(); - thread->m_id = ++m_idCounter; - m_idMutex->unlock(); -#elif defined(__LINUX__) +#if MTS_USE_ELF_TLS == 1 m_idMutex->lock(); m_id = ++m_idCounter; m_idMutex->unlock(); +#elif defined(__LINUX__) or defined(__OSX__) + m_idMutex->lock(); + thread->m_id = ++m_idCounter; + m_idMutex->unlock(); #endif try { @@ -263,22 +264,24 @@ void Thread::staticInitialization() { #endif m_self = new ThreadLocal(); + Thread *mainThread = new MainThread(); #if defined(__LINUX__) || defined(__OSX__) m_idMutex = new Mutex(); m_idCounter = 0; + + #if MTS_USE_ELF_TLS == 1 + m_id = 0; + #else + mainThread->m_id = 0; + #endif #endif - Thread *mainThread = new MainThread(); mainThread->m_running = true; mainThread->m_thread = pthread_self(); mainThread->m_joinMutex = new Mutex(); mainThread->m_joined = false; mainThread->m_fresolver = new FileResolver(); m_self->set(mainThread); -#if defined(__OSX__) - mainThread->m_id = 0; -#elif defined(__LINUX__) - m_id = 0; -#endif + } static std::vector __ompThreads; diff --git a/src/mtspy/base.cpp b/src/mtspy/base.cpp index 60de6edd..a3046ac0 100644 --- a/src/mtspy/base.cpp +++ b/src/mtspy/base.cpp @@ -65,6 +65,10 @@ BOOST_PYTHON_MODULE(mtspy) { def("initializeFramework", initializeFramework); def("shutdownFramework", shutdownFramework); + class_, boost::noncopyable>("Object"); +// .def("getRefCount", &Object::getRefCount) +// .def("toString", &Object::toString); + class_("Vector2", init()) .def(init()) .def(init()) diff --git a/src/shapes/SConscript b/src/shapes/SConscript index df50f195..c56fb341 100644 --- a/src/shapes/SConscript +++ b/src/shapes/SConscript @@ -2,7 +2,7 @@ Import('env', 'plugins') plugins += env.SharedLibrary('obj', ['obj.cpp']) plugins += env.SharedLibrary('ply', ['ply/ply.cpp', 'ply/ply_parser.cpp'], - CPPPATH = env['CPPPATH'] + ['ply']) + CPPPATH = env['CPPPATH'] + ['ply', '#dependencies']) plugins += env.SharedLibrary('serialized', ['serialized.cpp']) plugins += env.SharedLibrary('sphere', ['sphere.cpp']) plugins += env.SharedLibrary('cylinder', ['cylinder.cpp']) diff --git a/src/shapes/ply/ply.cpp b/src/shapes/ply/ply.cpp index 7267c51a..932338f0 100644 --- a/src/shapes/ply/ply.cpp +++ b/src/shapes/ply/ply.cpp @@ -23,16 +23,6 @@ #include #include -#if defined(__clang__) -#define MTS_USE_BOOST_TR1 (!__has_feature(cxx_variadic_templates)) -#else -# if defined(_MSC_VER) && (_MSC_VER < 1600) -# define MTS_USE_BOOST_TR1 1 -# else -# define MTS_USE_BOOST_TR1 0 -# endif -#endif - #if MTS_USE_BOOST_TR1 # if defined(Float) # define MTS_Float diff --git a/src/shapes/ply/ply/ply_parser.hpp b/src/shapes/ply/ply/ply_parser.hpp index a0f50a8d..8c22a88b 100644 --- a/src/shapes/ply/ply/ply_parser.hpp +++ b/src/shapes/ply/ply/ply_parser.hpp @@ -12,16 +12,21 @@ #if defined(__clang__) #define MTS_USE_BOOST_TR1 (!__has_feature(cxx_variadic_templates)) #else -# if defined(_MSC_VER) && (_MSC_VER < 1600) -# define MTS_USE_BOOST_TR1 1 +# if defined(_MSC_VER) +# if _MSC_VER < 1600 +# define MTS_USE_BOOST_TR1 1 +# else +# define MTS_USE_BOOST_TR1 0 +# endif # else -# define MTS_USE_BOOST_TR1 0 +# define MTS_USE_BOOST_TR1 0 # endif -#define ADT_WORKAROUND 1 #endif #if defined(__INTEL_COMPILER) #define ADT_WORKAROUND 1 +#else +#define ADT_WORKAROUND 0 #endif #if MTS_USE_BOOST_TR1 @@ -123,7 +128,7 @@ public: { return static_cast&>(callbacks_).callback; } -#if !defined(ADT_WORKAROUND) +#if ADT_WORKAROUND == 0 template friend typename scalar_property_definition_callback_type::type& at(scalar_property_definition_callbacks_type& scalar_property_definition_callbacks) { @@ -215,7 +220,7 @@ public: { return static_cast >&>(callbacks_).callback; } -#if !defined(ADT_WORKAROUND) +#if ADT_WORKAROUND == 0 template friend typename list_property_definition_callback_type::type& at(list_property_definition_callbacks_type& list_property_definition_callbacks) { @@ -554,7 +559,7 @@ inline bool ply::ply_parser::parse_list_property(format_type format, std::istrea } } -#if defined(ADT_WORKAROUND) +#if ADT_WORKAROUND == 1 // Horrible workaround for ADT failure as of Clang 2.8 namespace ply {