diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-09-03 16:20:38 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-09-03 16:20:38 +0200 |
commit | 0e2ae18a97fd507bac872031888d34c3a7d8b17b (patch) | |
tree | 3f9a551486969d2bc05f272e2da372c1a55d34cf /odb/details/win32/tls.hxx | |
parent | 137b1eb3e41578d9d4a066ef75c6abfa597c46cd (diff) |
Implement Win32 TLS support
Diffstat (limited to 'odb/details/win32/tls.hxx')
-rw-r--r-- | odb/details/win32/tls.hxx | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/odb/details/win32/tls.hxx b/odb/details/win32/tls.hxx new file mode 100644 index 0000000..b1dce0f --- /dev/null +++ b/odb/details/win32/tls.hxx @@ -0,0 +1,111 @@ +// file : odb/details/win32/tls.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_DETAILS_WIN32_TLS_HXX +#define ODB_DETAILS_WIN32_TLS_HXX + +#include <odb/pre.hxx> + +#include <cstddef> // std::size_t + +#include <odb/details/export.hxx> +#include <odb/details/win32/once.hxx> + +namespace odb +{ + namespace details + { + class LIBODB_EXPORT tls_common + { + public: + static std::size_t + _allocate (void (*dtor) (void*)); + + static void* + _get (std::size_t key); + + static void + _set (std::size_t key, void* value); + }; + + template <typename T> + class tls: protected tls_common + { + public: + tls (); + + T& + get () const; + + private: + tls (const tls&); + tls& operator= (const tls&); + + private: + static void + key_init (); + + static void + destructor (void*); + + private: + static once once_; + static std::size_t key_; + }; + + template <typename T> + class tls<T*>: protected tls_common + { + public: + tls (); + + T* + get () const; + + void + set (T* p); + + private: + tls (const tls&); + tls& operator= (const tls&); + + private: + static void + key_init (); + + private: + static once once_; + static std::size_t key_; + }; + + template <typename T> + inline T& + tls_get (const tls<T>& t) + { + return t.get (); + } + + template <typename T> + inline T* + tls_get (const tls<T*>& t) + { + return t.get (); + } + + template <typename T> + inline void + tls_set (tls<T*>& t, T* p) + { + t.set (p); + } + } +} + +#include <odb/details/win32/tls.ixx> +#include <odb/details/win32/tls.txx> + +#include <odb/post.hxx> + +#endif // ODB_DETAILS_WIN32_TLS_HXX |