From 0e2ae18a97fd507bac872031888d34c3a7d8b17b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 3 Sep 2010 16:20:38 +0200 Subject: Implement Win32 TLS support --- odb/details/win32/tls.hxx | 111 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 odb/details/win32/tls.hxx (limited to 'odb/details/win32/tls.hxx') 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 +// 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 + +#include // std::size_t + +#include +#include + +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 + 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 + class tls: 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 + inline T& + tls_get (const tls& t) + { + return t.get (); + } + + template + inline T* + tls_get (const tls& t) + { + return t.get (); + } + + template + inline void + tls_set (tls& t, T* p) + { + t.set (p); + } + } +} + +#include +#include + +#include + +#endif // ODB_DETAILS_WIN32_TLS_HXX -- cgit v1.1