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 |