linux compilation fixes for GCC 4.5

metadata
Wenzel Jakob 2011-08-13 20:41:19 -04:00
parent 4458a4e844
commit 9bd5619750
9 changed files with 53 additions and 44 deletions

View File

@ -1,7 +1,7 @@
BUILDDIR = '#build/debug' BUILDDIR = '#build/debug'
DISTDIR = '#dist' DISTDIR = '#dist'
CXX = 'g++' CXX = 'g++-4.5'
CC = 'gcc' 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'] 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 = [] LINKFLAGS = []
SHLINKFLAGS = ['-rdynamic', '-shared', '-fPIC'] SHLINKFLAGS = ['-rdynamic', '-shared', '-fPIC']

View File

@ -1,7 +1,7 @@
BUILDDIR = '#build/release' BUILDDIR = '#build/release'
DISTDIR = '#dist' DISTDIR = '#dist'
CXX = 'g++' CXX = 'g++-4.5'
CC = 'gcc' 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'] 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 = [] LINKFLAGS = []
SHLINKFLAGS = ['-rdynamic', '-shared', '-fPIC'] SHLINKFLAGS = ['-rdynamic', '-shared', '-fPIC']

View File

@ -130,6 +130,12 @@
/* Compile with Boost filesystem v2 */ /* Compile with Boost filesystem v2 */
#define BOOST_FILESYSTEM_VERSION 2 #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 <string> #include <string>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -80,12 +80,12 @@ public:
inline int getStackSize() const { return m_stackSize; } inline int getStackSize() const { return m_stackSize; }
/// Return the thread ID /// Return the thread ID
#if defined(__OSX__) #if defined(WIN32)
inline static int getID() { return getThread()->m_id; }
#elif defined(WIN32)
inline static int getID() { return (int) GetCurrentThreadId(); } inline static int getID() { return (int) GetCurrentThreadId(); }
#else #elif MTS_USE_ELF_TLS == 1
inline static int getID() { return m_id; } inline static int getID() { return m_id; }
#else
inline static int getID() { return getThread()->m_id; }
#endif #endif
/// Return the name of this thread /// Return the name of this thread
@ -184,11 +184,12 @@ private:
#if defined(__LINUX__) || defined(__OSX__) #if defined(__LINUX__) || defined(__OSX__)
static int m_idCounter; static int m_idCounter;
static ref<Mutex> m_idMutex; static ref<Mutex> m_idMutex;
#endif #if MTS_USE_ELF_TLS == 1
#if defined(__OSX__) static __thread int m_id
__attribute__((tls_model("global-dynamic")));
#else
int m_id; int m_id;
#elif defined(__LINUX__) #endif
static int __thread m_id;
#endif #endif
}; };

View File

@ -62,8 +62,9 @@ int Thread::m_idCounter;
ref<Mutex> Thread::m_idMutex; ref<Mutex> Thread::m_idMutex;
#endif #endif
#if defined(__LINUX__) #if MTS_USE_ELF_TLS == 1
int __thread __attribute__((tls_model("initial-exec"))) Thread::m_id; __thread int Thread::m_id
__attribute__((tls_model("global-dynamic")));
#endif #endif
Thread::Thread(const std::string &name, unsigned int stackSize) Thread::Thread(const std::string &name, unsigned int stackSize)
@ -155,14 +156,14 @@ void *Thread::dispatch(void *par) {
if (thread->getPriority() != ENormalPriority) if (thread->getPriority() != ENormalPriority)
thread->setPriority(thread->getPriority()); thread->setPriority(thread->getPriority());
#if defined(__OSX__) #if MTS_USE_ELF_TLS == 1
m_idMutex->lock();
thread->m_id = ++m_idCounter;
m_idMutex->unlock();
#elif defined(__LINUX__)
m_idMutex->lock(); m_idMutex->lock();
m_id = ++m_idCounter; m_id = ++m_idCounter;
m_idMutex->unlock(); m_idMutex->unlock();
#elif defined(__LINUX__) or defined(__OSX__)
m_idMutex->lock();
thread->m_id = ++m_idCounter;
m_idMutex->unlock();
#endif #endif
try { try {
@ -263,22 +264,24 @@ void Thread::staticInitialization() {
#endif #endif
m_self = new ThreadLocal<Thread>(); m_self = new ThreadLocal<Thread>();
Thread *mainThread = new MainThread();
#if defined(__LINUX__) || defined(__OSX__) #if defined(__LINUX__) || defined(__OSX__)
m_idMutex = new Mutex(); m_idMutex = new Mutex();
m_idCounter = 0; m_idCounter = 0;
#if MTS_USE_ELF_TLS == 1
m_id = 0;
#else
mainThread->m_id = 0;
#endif
#endif #endif
Thread *mainThread = new MainThread();
mainThread->m_running = true; mainThread->m_running = true;
mainThread->m_thread = pthread_self(); mainThread->m_thread = pthread_self();
mainThread->m_joinMutex = new Mutex(); mainThread->m_joinMutex = new Mutex();
mainThread->m_joined = false; mainThread->m_joined = false;
mainThread->m_fresolver = new FileResolver(); mainThread->m_fresolver = new FileResolver();
m_self->set(mainThread); m_self->set(mainThread);
#if defined(__OSX__)
mainThread->m_id = 0;
#elif defined(__LINUX__)
m_id = 0;
#endif
} }
static std::vector<OpenMPThread *> __ompThreads; static std::vector<OpenMPThread *> __ompThreads;

View File

@ -65,6 +65,10 @@ BOOST_PYTHON_MODULE(mtspy) {
def("initializeFramework", initializeFramework); def("initializeFramework", initializeFramework);
def("shutdownFramework", shutdownFramework); def("shutdownFramework", shutdownFramework);
class_<ref<Object>, boost::noncopyable>("Object");
// .def("getRefCount", &Object::getRefCount)
// .def("toString", &Object::toString);
class_<Vector2>("Vector2", init<Float, Float>()) class_<Vector2>("Vector2", init<Float, Float>())
.def(init<Float>()) .def(init<Float>())
.def(init<Point2>()) .def(init<Point2>())

View File

@ -2,7 +2,7 @@ Import('env', 'plugins')
plugins += env.SharedLibrary('obj', ['obj.cpp']) plugins += env.SharedLibrary('obj', ['obj.cpp'])
plugins += env.SharedLibrary('ply', ['ply/ply.cpp', 'ply/ply_parser.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('serialized', ['serialized.cpp'])
plugins += env.SharedLibrary('sphere', ['sphere.cpp']) plugins += env.SharedLibrary('sphere', ['sphere.cpp'])
plugins += env.SharedLibrary('cylinder', ['cylinder.cpp']) plugins += env.SharedLibrary('cylinder', ['cylinder.cpp'])

View File

@ -23,16 +23,6 @@
#include <mitsuba/core/timer.h> #include <mitsuba/core/timer.h>
#include <ply/ply_parser.hpp> #include <ply/ply_parser.hpp>
#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 MTS_USE_BOOST_TR1
# if defined(Float) # if defined(Float)
# define MTS_Float # define MTS_Float

View File

@ -12,16 +12,21 @@
#if defined(__clang__) #if defined(__clang__)
#define MTS_USE_BOOST_TR1 (!__has_feature(cxx_variadic_templates)) #define MTS_USE_BOOST_TR1 (!__has_feature(cxx_variadic_templates))
#else #else
# if defined(_MSC_VER) && (_MSC_VER < 1600) # if defined(_MSC_VER)
# define MTS_USE_BOOST_TR1 1 # if _MSC_VER < 1600
# define MTS_USE_BOOST_TR1 1
# else
# define MTS_USE_BOOST_TR1 0
# endif
# else # else
# define MTS_USE_BOOST_TR1 0 # define MTS_USE_BOOST_TR1 0
# endif # endif
#define ADT_WORKAROUND 1
#endif #endif
#if defined(__INTEL_COMPILER) #if defined(__INTEL_COMPILER)
#define ADT_WORKAROUND 1 #define ADT_WORKAROUND 1
#else
#define ADT_WORKAROUND 0
#endif #endif
#if MTS_USE_BOOST_TR1 #if MTS_USE_BOOST_TR1
@ -123,7 +128,7 @@ public:
{ {
return static_cast<callbacks_element<ScalarType>&>(callbacks_).callback; return static_cast<callbacks_element<ScalarType>&>(callbacks_).callback;
} }
#if !defined(ADT_WORKAROUND) #if ADT_WORKAROUND == 0
template <typename ScalarType> template <typename ScalarType>
friend typename scalar_property_definition_callback_type<ScalarType>::type& at(scalar_property_definition_callbacks_type& scalar_property_definition_callbacks) friend typename scalar_property_definition_callback_type<ScalarType>::type& at(scalar_property_definition_callbacks_type& scalar_property_definition_callbacks)
{ {
@ -215,7 +220,7 @@ public:
{ {
return static_cast<const callbacks_element<boost::mpl::pair<SizeType, ScalarType> >&>(callbacks_).callback; return static_cast<const callbacks_element<boost::mpl::pair<SizeType, ScalarType> >&>(callbacks_).callback;
} }
#if !defined(ADT_WORKAROUND) #if ADT_WORKAROUND == 0
template <typename SizeType, typename ScalarType> template <typename SizeType, typename ScalarType>
friend typename list_property_definition_callback_type<SizeType, ScalarType>::type& at(list_property_definition_callbacks_type& list_property_definition_callbacks) friend typename list_property_definition_callback_type<SizeType, ScalarType>::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 // Horrible workaround for ADT failure as of Clang 2.8
namespace ply namespace ply
{ {