diff options
Diffstat (limited to 'raul')
-rw-r--r-- | raul/Thread.hpp | 5 | ||||
-rw-r--r-- | raul/ThreadVar.hpp | 10 |
2 files changed, 6 insertions, 9 deletions
diff --git a/raul/Thread.hpp b/raul/Thread.hpp index 021bf86..0d6c094 100644 --- a/raul/Thread.hpp +++ b/raul/Thread.hpp @@ -39,11 +39,6 @@ class Thread : Noncopyable public: virtual ~Thread(); - /** Create a new thread. */ - static Thread* create(const std::string& name="") { - return new Thread(name); - } - /** Return the calling thread. * * If the calling thread does not yet have a Thread object associated with diff --git a/raul/ThreadVar.hpp b/raul/ThreadVar.hpp index 54e0d4e..eb6b63e 100644 --- a/raul/ThreadVar.hpp +++ b/raul/ThreadVar.hpp @@ -17,7 +17,6 @@ #ifndef RAUL_THREADVAR_HPP #define RAUL_THREADVAR_HPP -#include <stdlib.h> #include <pthread.h> namespace Raul { @@ -33,7 +32,7 @@ public: ThreadVar(const T& default_value) : _default_value(default_value) { - pthread_key_create(&_key, free); + pthread_key_create(&_key, destroy_value); } ~ThreadVar() { @@ -45,8 +44,7 @@ public: if (val) { *val = value; } else { - val = (T*)malloc(sizeof(value)); - *val = value; + val = new T(value); pthread_setspecific(_key, val); } return *this; @@ -61,6 +59,10 @@ private: ThreadVar(const ThreadVar& noncopyable); ThreadVar& operator=(const ThreadVar& noncopyable); + static void destroy_value(void* ptr) { + delete (T*)ptr; + } + const T _default_value; pthread_key_t _key; }; |