diff options
Diffstat (limited to 'odb/details/posix/tls.txx')
-rw-r--r-- | odb/details/posix/tls.txx | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/odb/details/posix/tls.txx b/odb/details/posix/tls.txx index 8cc78a4..189248b 100644 --- a/odb/details/posix/tls.txx +++ b/odb/details/posix/tls.txx @@ -32,9 +32,7 @@ namespace odb if (e != 0 || error_ != 0) throw posix_exception (e ? e : error_); - void* v (pthread_getspecific (key_)); - - if (v != 0) + if (void* v = pthread_getspecific (key_)) return *static_cast<T*> (v); std::auto_ptr<T> p (new T); @@ -49,6 +47,24 @@ namespace odb template <typename T> void tls<T>:: + free () + { + int e (pthread_once (&once_, key_init)); + + if (e != 0 || error_ != 0) + throw posix_exception (e ? e : error_); + + if (void* v = pthread_getspecific (key_)) + { + if (e = pthread_setspecific (key_, 0)) + throw posix_exception (e); + + delete static_cast<T*> (v); + } + } + + template <typename T> + void tls<T>:: key_init () { error_ = pthread_key_create (&key_, destructor); |