src/common.h

changeset 249
6b2cc2d82ba6
parent 248
4431371f3ffe
child 250
6e80f038e8df
equal deleted inserted replaced
248:4431371f3ffe 249:6b2cc2d82ba6
27 #include <stdlib.h> 27 #include <stdlib.h>
28 #include <assert.h> 28 #include <assert.h>
29 #include <vector> 29 #include <vector>
30 #include <stdint.h> 30 #include <stdint.h>
31 #include <stdarg.h> 31 #include <stdarg.h>
32 #include <QString>
33 #include <QMutex>
34
32 #include "string.h" 35 #include "string.h"
33 #include "config.h" 36 #include "config.h"
34 #include "types.h" 37 #include "types.h"
35 38
36 #define APPNAME "LDForge" 39 #define APPNAME "LDForge"
104 // Property with thread locking, use when multiple threads access the same property 107 // Property with thread locking, use when multiple threads access the same property
105 // Comes with a callback function for detecting when the value is changed. 108 // Comes with a callback function for detecting when the value is changed.
106 #define THREAD_PROPERTY(T, GET, SET) \ 109 #define THREAD_PROPERTY(T, GET, SET) \
107 private: \ 110 private: \
108 T m_##GET; \ 111 T m_##GET; \
109 bool m_threadLock_##GET; \ 112 QMutex m_threadLock_##GET; \
110 public: \ 113 public: \
111 const T& GET () const { \ 114 const T& GET () const { return m_##GET; } \
112 while (m_threadLock_##GET) \
113 ; \
114 return m_##GET; \
115 } \
116 void callback_##SET (); \ 115 void callback_##SET (); \
117 void SET (T val) { \ 116 void SET (T val) { \
118 while (m_threadLock_##GET) \ 117 m_threadLock_##GET.lock (); \
119 ; \
120 \
121 m_threadLock_##GET = true; \
122 m_##GET = val; \ 118 m_##GET = val; \
123 callback_##SET (); \ 119 callback_##SET (); \
124 m_threadLock_##GET = false; \ 120 m_threadLock_##GET.unlock (); \
125 } 121 }
126 122
127 #ifdef null 123 #ifdef null
128 #undef null 124 #undef null
129 #endif // null 125 #endif // null

mercurial