X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fthread.h;h=73e9beb806f44d8effc6dd8e3a3bec3f82adf23f;hb=e8fd1ce62331146fae0e98ce4a94d3720f308abf;hp=a32871aab87dfcb1f956c6d4ec86e8a0382c2b3e;hpb=e4bff8be94c0db4f94e63ad448d0eeb869ccdbbd;p=oweals%2Fminetest.git diff --git a/src/util/thread.h b/src/util/thread.h index a32871aab..73e9beb80 100644 --- a/src/util/thread.h +++ b/src/util/thread.h @@ -17,20 +17,20 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef UTIL_THREAD_HEADER -#define UTIL_THREAD_HEADER +#pragma once -#include "../irrlichttypes.h" -#include "../threading/thread.h" -#include "../threading/mutex.h" -#include "../threading/mutex_auto_lock.h" +#include "irrlichttypes.h" +#include "threading/thread.h" +#include "threading/mutex_auto_lock.h" #include "porting.h" #include "log.h" +#include "container.h" template -class MutexedVariable { +class MutexedVariable +{ public: - MutexedVariable(T value): + MutexedVariable(const T &value): m_value(value) {} @@ -40,23 +40,16 @@ public: return m_value; } - void set(T value) + void set(const T &value) { MutexAutoLock lock(m_mutex); m_value = value; } - // You'll want to grab this in a SharedPtr - MutexAutoLock *getLock() - { - return new MutexAutoLock(m_mutex); - } - // You pretty surely want to grab the lock when accessing this T m_value; - private: - Mutex m_mutex; + std::mutex m_mutex; }; /* @@ -85,11 +78,11 @@ public: template class GetRequest { public: - GetRequest() {} - ~GetRequest() {} + GetRequest() = default; + ~GetRequest() = default; - GetRequest(Key a_key) { - key = a_key; + GetRequest(const Key &a_key): key(a_key) + { } Key key; @@ -111,7 +104,7 @@ public: return m_queue.empty(); } - void add(Key key, Caller caller, CallerData callerdata, + void add(const Key &key, Caller caller, CallerData callerdata, ResultQueue *dest) { typename std::deque >::iterator i; @@ -196,7 +189,7 @@ class UpdateThread : public Thread { public: UpdateThread(const std::string &name) : Thread(name + "Update") {} - ~UpdateThread() {} + ~UpdateThread() = default; void deferUpdate() { m_update_sem.post(); } @@ -210,7 +203,6 @@ public: void *run() { - DSTACK(__FUNCTION_NAME); BEGIN_DEBUG_EXCEPTION_HANDLER while (!stopRequested()) { @@ -223,7 +215,7 @@ public: doUpdate(); } - END_DEBUG_EXCEPTION_HANDLER(errorstream) + END_DEBUG_EXCEPTION_HANDLER return NULL; } @@ -234,6 +226,3 @@ protected: private: Semaphore m_update_sem; }; - -#endif -