diff options
author | David Robillard <d@drobilla.net> | 2012-05-14 06:05:48 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-05-14 06:05:48 +0000 |
commit | b85ad0bc4e96566d8f936295e36fae2eef99d356 (patch) | |
tree | 8f0de609e77387b51e76a9be5bb7290d85f81194 /raul | |
parent | ff4c3ff14e76e5b06f1b4c44f03f900e1bd4ac50 (diff) | |
download | raul-b85ad0bc4e96566d8f936295e36fae2eef99d356.tar.gz raul-b85ad0bc4e96566d8f936295e36fae2eef99d356.tar.bz2 raul-b85ad0bc4e96566d8f936295e36fae2eef99d356.zip |
Remove useless Thread::create().
Use safer C++isms for value allocation in ThreadVar.
Test ThreadVar.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4412 a436a847-0d15-0410-975c-d299462d15a1
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; }; |