summaryrefslogtreecommitdiff
path: root/src/jthread/jthread.h
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2014-01-31 22:16:47 +0100
committersapier <Sapier at GMX dot net>2014-04-19 10:05:23 +0200
commitea0df3e4cb75a7a104a81e050c019049219c4fee (patch)
tree02ad409cc7e5b988b2b6093868723b39f9b61dba /src/jthread/jthread.h
parentc00ed9dac3e3bed36ea06d80fc9856927f1cca95 (diff)
downloadminetest-ea0df3e4cb75a7a104a81e050c019049219c4fee.tar.gz
minetest-ea0df3e4cb75a7a104a81e050c019049219c4fee.tar.bz2
minetest-ea0df3e4cb75a7a104a81e050c019049219c4fee.zip
jthread remove locks that aren't absolutely required
add c++11 atomic support (optional)
Diffstat (limited to 'src/jthread/jthread.h')
-rw-r--r--src/jthread/jthread.h38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/jthread/jthread.h b/src/jthread/jthread.h
index f7bce6f9a..89743a3e3 100644
--- a/src/jthread/jthread.h
+++ b/src/jthread/jthread.h
@@ -26,9 +26,12 @@
*/
#ifndef JTHREAD_H
-
#define JTHREAD_H
+#if __cplusplus >= 201103L
+#include <atomic>
+#endif
+
#include "jthread/jmutex.h"
#define ERR_JTHREAD_CANTINITMUTEX -1
@@ -43,11 +46,14 @@ public:
JThread();
virtual ~JThread();
int Start();
- void Stop();
+ inline void Stop()
+ { requeststop = true; }
int Kill();
virtual void *Thread() = 0;
- bool IsRunning();
- bool StopRequested();
+ inline bool IsRunning()
+ { return running; }
+ inline bool StopRequested()
+ { return requeststop; }
void *GetReturnValue();
bool IsSameThread();
@@ -75,13 +81,35 @@ private:
pthread_t threadid;
+ /*
+ * reading and writing bool values is atomic on all relevant architectures
+ * ( x86 + arm ). No need to waste time for locking here.
+ * once C++11 is supported we can tell compiler to handle cpu caches correct
+ * too. This should cause additional improvement (and silence thread
+ * concurrency check tools.
+ */
+#if __cplusplus >= 201103L
+ std::atomic_bool started;
+#else
bool started;
+#endif
#endif // WIN32
void *retval;
+ /*
+ * reading and writing bool values is atomic on all relevant architectures
+ * ( x86 + arm ). No need to waste time for locking here.
+ * once C++11 is supported we can tell compiler to handle cpu caches correct
+ * too. This should cause additional improvement (and silence thread
+ * concurrency check tools.
+ */
+#if __cplusplus >= 201103L
+ std::atomic_bool running;
+ std::atomic_bool requeststop;
+#else
bool running;
bool requeststop;
+#endif
- JMutex runningmutex;
JMutex continuemutex,continuemutex2;
};