summaryrefslogtreecommitdiff
path: root/src/util/thread.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/thread.h')
-rw-r--r--src/util/thread.h60
1 files changed, 24 insertions, 36 deletions
diff --git a/src/util/thread.h b/src/util/thread.h
index b3a5e68a2..a32871aab 100644
--- a/src/util/thread.h
+++ b/src/util/thread.h
@@ -21,9 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define UTIL_THREAD_HEADER
#include "../irrlichttypes.h"
-#include "../jthread/jthread.h"
-#include "../jthread/jmutex.h"
-#include "../jthread/jmutexautolock.h"
+#include "../threading/thread.h"
+#include "../threading/mutex.h"
+#include "../threading/mutex_auto_lock.h"
#include "porting.h"
#include "log.h"
@@ -36,27 +36,27 @@ public:
T get()
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
return m_value;
}
void set(T value)
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
m_value = value;
}
// You'll want to grab this in a SharedPtr
- JMutexAutoLock *getLock()
+ MutexAutoLock *getLock()
{
- return new JMutexAutoLock(m_mutex);
+ return new MutexAutoLock(m_mutex);
}
// You pretty surely want to grab the lock when accessing this
T m_value;
private:
- JMutex m_mutex;
+ Mutex m_mutex;
};
/*
@@ -118,7 +118,7 @@ public:
typename std::list<CallerInfo<Caller, CallerData, Key, T> >::iterator j;
{
- JMutexAutoLock lock(m_queue.getMutex());
+ MutexAutoLock lock(m_queue.getMutex());
/*
If the caller is already on the list, only update CallerData
@@ -192,44 +192,33 @@ private:
MutexedQueue<GetRequest<Key, T, Caller, CallerData> > m_queue;
};
-class UpdateThread : public JThread {
+class UpdateThread : public Thread
+{
public:
- UpdateThread() {}
- virtual ~UpdateThread() {}
+ UpdateThread(const std::string &name) : Thread(name + "Update") {}
+ ~UpdateThread() {}
- void deferUpdate()
- {
- m_update_sem.Post();
- }
+ void deferUpdate() { m_update_sem.post(); }
- void Stop()
+ void stop()
{
- JThread::Stop();
+ Thread::stop();
// give us a nudge
- m_update_sem.Post();
+ m_update_sem.post();
}
- void *Thread()
+ void *run()
{
- ThreadStarted();
-
- const char *thread_name = getName();
- log_register_thread(thread_name);
- porting::setThreadName(thread_name);
-
DSTACK(__FUNCTION_NAME);
BEGIN_DEBUG_EXCEPTION_HANDLER
- while (!StopRequested()) {
- m_update_sem.Wait();
-
- // Empty the queue, just in case doUpdate() is expensive
- while (m_update_sem.GetValue())
- m_update_sem.Wait();
+ while (!stopRequested()) {
+ m_update_sem.wait();
+ // Set semaphore to 0
+ while (m_update_sem.wait(0));
- if (StopRequested())
- break;
+ if (stopRequested()) break;
doUpdate();
}
@@ -241,10 +230,9 @@ public:
protected:
virtual void doUpdate() = 0;
- virtual const char *getName() = 0;
private:
- JSemaphore m_update_sem;
+ Semaphore m_update_sem;
};
#endif