diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | m4/threads.m4 | 20 | ||||
-rw-r--r-- | odb/Makefile.am | 4 | ||||
-rw-r--r-- | odb/details/config.h.in | 2 | ||||
-rw-r--r-- | odb/details/tls.hxx | 28 |
5 files changed, 53 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index c1e7cfa..eb71db7 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,8 @@ AS_IF([test x$threads = xnone], AC_DEFINE([ODB_THREADS_NONE], [1], [Have no thre AS_IF([test x$threads = xwin32], AC_DEFINE([ODB_THREADS_WIN32], [1], [Have Win32 threads.])) AS_IF([test x$threads = xposix], AC_DEFINE([ODB_THREADS_POSIX], [1], [Have POSIX threads.])) +AS_IF([test x$threads_thread_keyword = xyes], AC_DEFINE([ODB_THREADS_TLS_KEYWORD], [1], [Have __thread keyword.])) + # Define LIBODB_STATIC_LIB if we are build static library on certain platforms. # STATIC_LIB([LIBODB_STATIC_LIB], [Static library interface.]) diff --git a/m4/threads.m4 b/m4/threads.m4 index 7c32abe..ea547c0 100644 --- a/m4/threads.m4 +++ b/m4/threads.m4 @@ -5,6 +5,8 @@ dnl license : GNU GPL v2; see accompanying LICENSE file dnl AC_DEFUN([THREADS],[ +threads_thread_keyword=no + AC_ARG_ENABLE( [threads], AS_HELP_STRING([--disable-threads], [disable threads (enabled by default)]), @@ -30,6 +32,24 @@ if test x$threads = xcheck; then threads=posix LIBS="$LIBS $PTHREAD_LIBS" CXXFLAGS="$CXXFLAGS $PTHREAD_CXXFLAGS" + + # Check if we can use the __thread keyword. + # + AC_MSG_CHECKING([for __thread keyword]) + + CXX_LIBTOOL_LINK_IFELSE( + AC_LANG_SOURCE([[ + __thread int tls_var; + + int + main () + { + tls_var = 0; + } + ]]), + [threads_thread_keyword=yes]) + + AC_MSG_RESULT([$threads_thread_keyword]) fi ;; esac diff --git a/odb/Makefile.am b/odb/Makefile.am index 9922a37..d671b16 100644 --- a/odb/Makefile.am +++ b/odb/Makefile.am @@ -22,5 +22,5 @@ libodb_la_SOURCES += __path__(win32_sources) __path__(win32_dll_sources) nobase_odbinclude_HEADERS += __path__(win32_headers) endif -libodb_la_CPPFLAGS= -I'$(top_builddir)' -I'$(top_srcdir)' -DLIBODB_DYNAMIC_LIB -libodb_la_LDFLAGS = -release __value__(interface_version) -no-undefined +AM_CPPFLAGS= -I'$(top_builddir)' -I'$(top_srcdir)' -DLIBODB_DYNAMIC_LIB +AM_LDFLAGS = -release __value__(interface_version) -no-undefined diff --git a/odb/details/config.h.in b/odb/details/config.h.in index a55352a..acab724 100644 --- a/odb/details/config.h.in +++ b/odb/details/config.h.in @@ -12,6 +12,8 @@ #undef ODB_THREADS_NONE #undef ODB_THREADS_POSIX #undef ODB_THREADS_WIN32 +#undef ODB_THREADS_TLS_KEYWORD +#undef ODB_THREADS_TLS_DECLSPEC #undef LIBODB_STATIC_LIB diff --git a/odb/details/tls.hxx b/odb/details/tls.hxx index 2ed68ab..2c19081 100644 --- a/odb/details/tls.hxx +++ b/odb/details/tls.hxx @@ -54,7 +54,33 @@ namespace odb #elif defined(ODB_THREADS_POSIX) # include <odb/details/posix/tls.hxx> -# define ODB_TLS_POINTER(type) tls<type*> + +# ifdef ODB_THREADS_TLS_KEYWORD +# define ODB_TLS_POINTER(type) __thread type* + +namespace odb +{ + namespace details + { + template <typename T> + inline T* + tls_get (T* p) + { + return p; + } + + template <typename T> + inline void + tls_set (T*& rp, T* p) + { + rp = p; + } + } +} + +# else +# define ODB_TLS_POINTER(type) tls<type*> +# endif # define ODB_TLS_OBJECT(type) tls<type> #elif defined(ODB_THREADS_WIN32) |