From b85ad0bc4e96566d8f936295e36fae2eef99d356 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 14 May 2012 06:05:48 +0000 Subject: 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 --- raul/Thread.hpp | 5 ----- raul/ThreadVar.hpp | 10 ++++++---- 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'raul') 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 #include 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; }; -- cgit v1.2.1