34 class QSocketNotifier;
44 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
48 #define kvi_mutex_t HANDLE
49 inline void kvi_threadMutexInit(kvi_mutex_t * _pMutex_t)
51 *_pMutex_t = CreateMutex(0, 0,
NULL);
53 #define kvi_threadMutexLock(_pMutex_t) WaitForSingleObject(*_pMutex_t, INFINITE)
54 #define kvi_threadMutexUnlock(_pMutex_t) ReleaseMutex(*_pMutex_t)
55 #define kvi_threadMutexDestroy(_pMutex_t) CloseHandle(*_pMutex_t)
56 inline bool kvi_threadMutexTryLock(kvi_mutex_t * _pMutex_t)
58 return (WaitForSingleObject(*_pMutex_t, 0) == WAIT_OBJECT_0);
61 #define kvi_thread_t HANDLE
63 inline bool kvi_threadCreate(kvi_thread_t *
t, LPTHREAD_START_ROUTINE start_routine,
void * arg)
66 *t = CreateThread(
NULL, 0, start_routine, arg, 0, &dwThreadId);
70 #define kvi_threadExit() ExitThread(0)
73 #ifdef COMPILE_THREADS_USE_POSIX
80 #define kvi_mutex_t pthread_mutex_t
81 #define kvi_threadMutexInit(_pMutex_t) pthread_mutex_init(_pMutex_t, 0)
82 #define kvi_threadMutexLock(_pMutex_t) pthread_mutex_lock(_pMutex_t)
83 #define kvi_threadMutexUnlock(_pMutex_t) pthread_mutex_unlock(_pMutex_t)
84 #define kvi_threadMutexDestroy(_pMutex_t) pthread_mutex_destroy(_pMutex_t)
85 inline bool kvi_threadMutexTryLock(kvi_mutex_t * _pMutex_t)
87 return (pthread_mutex_trylock(_pMutex_t) != EBUSY);
93 #define kvi_thread_t pthread_t
95 inline bool kvi_threadCreate(kvi_thread_t * t,
void * (*start_routine)(
void *),
void * arg)
98 pthread_attr_init(&a);
99 pthread_attr_setinheritsched(&a, PTHREAD_INHERIT_SCHED);
100 pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
102 int ret = pthread_create(t, &a, start_routine, arg);
104 pthread_attr_destroy(&a);
109 #define kvi_threadExit() pthread_exit(0)
111 #ifdef COMPILE_THREADS_USE_SOLARIS_LIBTHREAD
118 #define kvi_mutex_t mutex_t
119 #define kvi_threadMutexInit(_pMutex_t) mutex_init(_pMutex_t, 0, 0)
120 #define kvi_threadMutexLock(_pMutex_t) mutex_lock(_pMutex_t)
121 #define kvi_threadMutexUnlock(_pMutex_t) mutex_unlock(_pMutex_t)
122 #define kvi_threadMutexDestroy(_pMutex_t) mutex_destroy(_pMutex_t)
123 inline bool kvi_threadMutexTryLock(kvi_mutex_t * _pMutex_t)
125 return (mutex_trylock(_pMutex_t) != EBUSY);
131 #define kvi_thread_t thread_t
133 inline bool kvi_threadCreate(kvi_thread_t * t,
void * (*start_routine)(
void *),
void * arg)
135 return (thr_create(0, 0, start_routine, arg, THR_DETACHED, t) == 0);
139 #define kvi_threadExit() thr_exit(0)
150 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
155 virtual ~KviMutex() { kvi_threadMutexDestroy(&m_mutex); };
157 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
160 kvi_threadMutexLock(&m_mutex);
166 kvi_threadMutexUnlock(&m_mutex);
168 bool locked() {
return m_bLocked; };
172 kvi_threadMutexLock(&m_mutex);
174 void unlock() { kvi_threadMutexUnlock(&m_mutex); };
213 void internalThreadRun_doNotTouchThis();
215 static void sleep(
unsigned long sec);
216 static void msleep(
unsigned long msec);
217 static void usleep(
unsigned long usec);
229 void postEvent(QObject *
o, QEvent *
e);
232 void setRunning(
bool bRunning);
233 void setStartingUp(
bool bStartingUp);
237 #define KVI_THREAD_EVENT (((int)QEvent::User) + 2000)
248 #define KVI_THREAD_EVENT_TERMINATE 0
256 #define KVI_THREAD_EVENT_SUCCESS 100
259 #define KVI_THREAD_EVENT_STATECHANGE 150
262 #define KVI_THREAD_EVENT_MESSAGE 200
263 #define KVI_THREAD_EVENT_WARNING 201
264 #define KVI_THREAD_EVENT_ERROR 202
265 #define KVI_THREAD_EVENT_DATA 203
268 #define KVI_THREAD_EVENT_BINARYDATA 300
271 #define KVI_THREAD_USER_EVENT_BASE 1000
284 : QEvent((QEvent::Type)
KVI_THREAD_EVENT), m_eventId(evId), m_pSender(sender){};
291 int id() {
return m_eventId; };
294 template <
class TData>
381 static void killPendingEvents(QObject * receiver);
384 #if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW)
390 #if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW)
398 void unregisterSlaveThread(
KviThread * t);
400 void threadEnteredWaitState();
401 void threadLeftWaitState();
403 void postSlaveEvent(QObject *
o, QEvent *
e);
404 void killPendingEventsByReceiver(QObject * receiver);
406 static void globalInit();
407 static void globalDestroy();
409 void eventsPending(
int fd);
QSocketNotifier * m_pSn
Definition: KviThread.h:385
Definition: KviHeapObject.h:124
void setData(TData *d)
Definition: KviThread.h:310
KviMutex * m_pLocalEventQueueMutex
Definition: KviThread.h:340
TData * data()
Definition: KviThread.h:322
KviThreadDataEvent(int evId, TData *pData=0, KviThread *sender=0)
Definition: KviThread.h:301
KviThread * m_pSender
Definition: KviThread.h:280
#define a
Definition: detector.cpp:91
struct _KviThreadPendingEvent KviThreadPendingEvent
char * NULL
Definition: KviIrcNumericCodes.h:391
kvi_mutex_t m_mutex
Definition: KviThread.h:149
TData * m_pData
Definition: KviThread.h:298
KviMutex * m_pRunningMutex
Definition: KviThread.h:192
virtual ~KviThreadEvent()
Definition: KviThread.h:285
QObject * o
Definition: KviThread.h:365
virtual ~KviThreadDataEvent()
Definition: KviThread.h:303
KviPointerList< KviThreadEvent > * m_pLocalEventQueue
Definition: KviThread.h:341
Definition: KviThread.h:146
Definition: KviThread.h:369
#define e
Definition: detector.cpp:69
KviPointerList< QEvent > * m_pLocalEventQueue
Definition: KviThread.h:193
kvi_thread_t m_thread
Definition: KviThread.h:189
KviThread * sender()
Definition: KviThread.h:290
void lock()
Definition: KviThread.h:170
virtual void run()
Definition: KviThread.h:224
char s d
Definition: KviIrcNumericCodes.h:391
Definition: KviThread.h:182
bool m_bStartingUp
Definition: KviThread.h:191
int m_iTriggerCount
Definition: KviThread.h:393
KviMutex * m_pMutex
Definition: KviThread.h:387
TData * getData()
Definition: KviThread.h:316
KviPointerList< KviThreadPendingEvent > * m_pEventQueue
Definition: KviThread.h:391
Definition: KviThread.h:276
int id()
Definition: KviThread.h:291
QHashIterator< int, QFile * > t(getDict)
KviMutex()
Definition: KviThread.h:154
Definition: KviThread.h:295
C++ Template based double linked pointer list class.
virtual ~KviMutex()
Definition: KviThread.h:155
int m_eventId
Definition: KviThread.h:279
Definition: KviApplication.h:102
#define o
Definition: detector.cpp:79
#define KVI_THREAD_EVENT
Definition: KviThread.h:237
QEvent * e
Definition: KviThread.h:366
KviThreadEvent(int evId, KviThread *sender=0)
Definition: KviThread.h:283
void unlock()
Definition: KviThread.h:174
int m_iWaitingThreads
Definition: KviThread.h:389
KviPointerList< KviThread > * m_pThreadList
Definition: KviThread.h:388
This file contains compile time settings.
Definition: KviThread.h:333
bool m_bRunning
Definition: KviThread.h:190
Definition: KviThread.h:363
#define KVILIB_API
Definition: kvi_settings.h:125