22 #define threadid_t Qt::HANDLE
23 inline threadid_t threadID() {
return QThread::currentThreadId();}
24 #define is_thread_equal(x,y) ((x) == (y))
26 #include <QWaitCondition>
28 #elif defined USE_PTHREAD
29 #define threadid_t pthread_t
30 inline threadid_t threadID() {
return pthread_self();}
31 #define is_thread_equal(x,y) (pthread_equal(x,y))
37 #include "threadlocal.h"
40 template <
class Mutex>
42 explicit XScopedLock(Mutex &mutex) : m_mutex(mutex) {
53 template <
class Mutex>
56 m_bLocking = m_mutex.trylock();
59 if(m_bLocking) m_mutex.unlock();
61 bool operator!()
const {
64 operator bool()
const {
88 #elif defined USE_PTHREAD
89 pthread_mutex_t m_mutex;
103 int wait(
int usec = 0);
112 QWaitCondition m_cond;
113 #elif defined USE_PTHREAD
114 pthread_cond_t m_cond;
122 m_lockingthread = (threadid_t)-1;
127 if(!is_thread_equal(m_lockingthread, threadID())) {
130 m_lockingthread = threadID();
138 if(m_lockcount == 0) {
139 m_lockingthread = (threadid_t)-1;
145 if(!is_thread_equal(m_lockingthread, threadID())) {
146 if(m_mutex.trylock()) {
148 m_lockingthread = threadID();
159 return is_thread_equal(m_lockingthread, threadID());
163 threadid_t m_lockingthread;
184 void waitFor(
void **retval = 0L);
191 shared_ptr<targ> this_ptr;
196 shared_ptr<targ> m_startarg;
197 static void * xthread_start_routine(
void *);
199 pthread_t m_threadid;
200 #elif defined USE_STD_THREAD
201 std::thread m_thread;
210 : m_startarg(std::make_shared<
targ>()) {
211 m_startarg->obj = dynamic_pointer_cast<T>(t);
212 assert(m_startarg->obj);
213 m_startarg->func = func;
214 m_startarg->is_terminated =
false;
220 #if defined USE_STD_THREAD
221 if(m_thread.joinable()) {
230 m_startarg->this_ptr = m_startarg;
233 pthread_create((pthread_t*)&m_threadid, NULL,
236 #elif defined USE_STD_THREAD
244 shared_ptr<targ> arg = ((targ *)x)->this_ptr;
245 if(isMemLockAvailable())
248 arg->this_ptr.reset();
249 void *p = ((arg->obj.get())->*(arg->func))(arg->is_terminated);
255 #include <system_error>
261 pthread_join(m_threadid, retval);
262 #elif defined USE_STD_THREAD
269 m_startarg->is_terminated =
true;