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.txx | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 odb/details/win32/tls.txx (limited to 'odb/details/win32/tls.txx') diff --git a/odb/details/win32/tls.txx b/odb/details/win32/tls.txx new file mode 100644 index 0000000..f20b6a9 --- /dev/null +++ b/odb/details/win32/tls.txx @@ -0,0 +1,87 @@ +// file : odb/details/win32/tls.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::auto_ptr + +#include + +using namespace std; + +namespace odb +{ + namespace details + { + // tls + // + template + once tls::once_; + + template + size_t tls::key_; + + template + T& tls:: + get () const + { + once_.call (key_init); + void* v (_get (key_)); + + if (v != 0) + return *static_cast (v); + + auto_ptr p (new T); + _set (key_, p.get ()); + + T& r (*p); + p.release (); + return r; + } + + template + void tls:: + key_init () + { + key_ = _allocate (destructor); + } + + template + void tls:: + destructor (void* v) + { + delete static_cast (v); + } + + // tls + // + template + once tls::once_; + + template + size_t tls::key_; + + template + T* tls:: + get () const + { + once_.call (key_init); + return static_cast (_get (key_)); + } + + template + void tls:: + set (T* p) + { + once_.call (key_init); + _set (key_, p); + } + + template + void tls:: + key_init () + { + key_ = _allocate (0); + } + } +} -- cgit v1.1