diff options
Diffstat (limited to 'odb/details/tls.hxx')
-rw-r--r-- | odb/details/tls.hxx | 98 |
1 files changed, 95 insertions, 3 deletions
diff --git a/odb/details/tls.hxx b/odb/details/tls.hxx index 6d38e6b..7ce5c19 100644 --- a/odb/details/tls.hxx +++ b/odb/details/tls.hxx @@ -6,9 +6,101 @@ #ifndef ODB_DETAILS_TLS_HXX #define ODB_DETAILS_TLS_HXX -#include <odb/details/posix/tls.hxx> +#include <odb/pre.hxx> -#define ODB_TLS_POINTER(type) tls<type*> -#define ODB_TLS_OBJECT(type) tls<type> +#include <odb/details/config.hxx> + +#ifdef ODB_THREADS_NONE + +# define ODB_TLS_POINTER(type) type* +# define ODB_TLS_OBJECT(type) type + +namespace odb +{ + namespace details + { + template <typename T> + inline T& + tls_get (T& x) + { + return x; + } + + template <typename T> + inline T* + tls_get (T* p) + { + return p; + } + + template <typename T> + inline void + tls_set (T*& rp, T* p) + { + rp = p; + } + } +} + +#elif defined(ODB_THREADS_POSIX) + +# include <odb/details/posix/tls.hxx> +# define ODB_TLS_POINTER(type) tls<type*> +# define ODB_TLS_OBJECT(type) tls<type> + +#elif defined(ODB_THREADS_WIN32) + +# ifdef ODB_THREADS_TLS_DECLSPEC_POINTER +# define ODB_TLS_POINTER(type) __declspec(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 +# error unsupported TLS pointer model +# endif + +# ifdef ODB_THREADS_TLS_DECLSPEC_OBJECT +# define ODB_TLS_OBJECT(type) __declspec(thread) type + +namespace odb +{ + namespace details + { + template <typename T> + inline T& + tls_get (T& x) + { + return x; + } + } +} + +# else +# error unsupported TLS object model +# endif + +#else +# error unknown threading model +#endif + +#include <odb/post.hxx> #endif // ODB_DETAILS_TLS_HXX |