summaryrefslogtreecommitdiffstats
path: root/raul/ThreadVar.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-09-20 15:26:45 -0400
committerDavid Robillard <d@drobilla.net>2016-09-26 13:09:10 -0400
commitf8bf77d3c3b77830aedafb9ebb5cdadfea7ed07a (patch)
tree4b191728aa88b9e83080b07f4e391a62229168e9 /raul/ThreadVar.hpp
parent537debda2bba0f97734602a95d412569fb607efb (diff)
downloadraul-f8bf77d3c3b77830aedafb9ebb5cdadfea7ed07a.tar.gz
raul-f8bf77d3c3b77830aedafb9ebb5cdadfea7ed07a.tar.bz2
raul-f8bf77d3c3b77830aedafb9ebb5cdadfea7ed07a.zip
Remove features now provided by C++11
Diffstat (limited to 'raul/ThreadVar.hpp')
-rw-r--r--raul/ThreadVar.hpp75
1 files changed, 0 insertions, 75 deletions
diff --git a/raul/ThreadVar.hpp b/raul/ThreadVar.hpp
deleted file mode 100644
index fa714bd..0000000
--- a/raul/ThreadVar.hpp
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- This file is part of Raul.
- Copyright 2007-2016 David Robillard <http://drobilla.net>
-
- Raul is free software: you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation, either version 3 of the License, or any later version.
-
- Raul is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Raul. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef RAUL_THREADVAR_HPP
-#define RAUL_THREADVAR_HPP
-
-#include <pthread.h>
-
-#include "raul/Noncopyable.hpp"
-
-namespace Raul {
-
-/** Thread-specific variable.
- *
- * A ThreadVar is a variable which has a different value for each thread.
- */
-template<typename T>
-class ThreadVar : public Noncopyable
-{
-public:
- explicit ThreadVar(const T& default_value)
- : _default_value(default_value)
- {
- pthread_key_create(&_key, destroy_value);
- }
-
- ~ThreadVar() {
- T* val = (T*)pthread_getspecific(_key);
- delete val;
- pthread_key_delete(_key);
- }
-
- /** Set the value for the calling thread. */
- ThreadVar& operator=(const T& value) {
- T* val = (T*)pthread_getspecific(_key);
- if (val) {
- *val = value;
- } else {
- val = new T(value);
- pthread_setspecific(_key, val);
- }
- return *this;
- }
-
- /** Get the value for the calling thread. */
- operator T() const {
- T* val = (T*)pthread_getspecific(_key);
- return val ? *val : _default_value;
- }
-
-private:
- static void destroy_value(void* ptr) {
- delete (T*)ptr;
- }
-
- const T _default_value;
- pthread_key_t _key;
-};
-
-} // namespace Raul
-
-#endif // RAUL_THREADVAR_HPP