Replace stray tab with whitespace in guiFormSpecMenu.cpp (#9317)
[oweals/minetest.git] / src / util / thread.h
index a32871aab87dfcb1f956c6d4ec86e8a0382c2b3e..73e9beb806f44d8effc6dd8e3a3bec3f82adf23f 100644 (file)
@@ -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<typename T>
-class MutexedVariable {
+class MutexedVariable
+{
 public:
-       MutexedVariable(value):
+       MutexedVariable(const T &value):
                m_value(value)
        {}
 
@@ -40,23 +40,16 @@ public:
                return m_value;
        }
 
-       void set(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<typename Key, typename T, typename Caller, typename CallerData>
 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<Key, T, Caller, CallerData> *dest)
        {
                typename std::deque<GetRequest<Key, T, Caller, CallerData> >::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
-