diff options
Diffstat (limited to 'odb/details/win32')
-rw-r--r-- | odb/details/win32/tls.cxx | 4 | ||||
-rw-r--r-- | odb/details/win32/tls.hxx | 10 | ||||
-rw-r--r-- | odb/details/win32/tls.txx | 16 |
3 files changed, 28 insertions, 2 deletions
diff --git a/odb/details/win32/tls.cxx b/odb/details/win32/tls.cxx index d6dc2d8..29eb5fb 100644 --- a/odb/details/win32/tls.cxx +++ b/odb/details/win32/tls.cxx @@ -18,6 +18,10 @@ #include <odb/details/win32/tls-init.hxx> #include <odb/details/win32/exceptions.hxx> +#ifdef _MSC_VER +# pragma warning (disable:4200) // zero-sized array in struct +#endif + using namespace std; namespace odb diff --git a/odb/details/win32/tls.hxx b/odb/details/win32/tls.hxx index b1dce0f..3354723 100644 --- a/odb/details/win32/tls.hxx +++ b/odb/details/win32/tls.hxx @@ -39,6 +39,9 @@ namespace odb T& get () const; + void + free (); + private: tls (const tls&); tls& operator= (const tls&); @@ -88,6 +91,13 @@ namespace odb } template <typename T> + inline void + tls_free (tls<T>& t) + { + t.free (); + } + + template <typename T> inline T* tls_get (const tls<T*>& t) { diff --git a/odb/details/win32/tls.txx b/odb/details/win32/tls.txx index f20b6a9..025e7cb 100644 --- a/odb/details/win32/tls.txx +++ b/odb/details/win32/tls.txx @@ -26,9 +26,8 @@ namespace odb get () const { once_.call (key_init); - void* v (_get (key_)); - if (v != 0) + if (void* v = _get (key_)) return *static_cast<T*> (v); auto_ptr<T> p (new T); @@ -41,6 +40,19 @@ namespace odb template <typename T> void tls<T>:: + free () + { + once_.call (key_init); + + if (void* v = _get (key_)) + { + _set (key_, 0); + delete static_cast<T*> (v); + } + } + + template <typename T> + void tls<T>:: key_init () { key_ = _allocate (destructor); |