26 #include <tqptrlist.h>
28 #include <tqwaitcondition.h>
32 #include <kdemacros.h>
35 namespace ThreadWeaver {
53 KDE_EXPORT
extern bool Debug;
54 KDE_EXPORT
extern int DebugLevel;
56 KDE_EXPORT
inline void setDebugLevel (
bool debug,
int level)
62 KDE_EXPORT
inline void debug(
int severity,
const char * cformat, ...)
64 __attribute__ ( (format (printf, 2, 3 ) ) )
68 KDE_EXPORT
inline void debug(
int severity,
const char * cformat, ...)
70 if ( Debug ==
true && ( severity<=DebugLevel || severity == 0) )
77 va_start( ap, cformat );
78 vprintf (cformat, ap);
99 class KDE_EXPORT
Event :
public TQCustomEvent
123 Action action ()
const;
128 static const int Type;
163 class KDE_EXPORT
Job :
public TQObject
169 Job(TQObject* parent=0,
const char* name=0);
178 virtual void execute(
Thread*);
181 virtual bool isFinished()
const;
188 virtual void processEvent (
Event* );
224 virtual void setFinished(
bool status);
242 TQWaitCondition *m_wc;
249 class KDE_EXPORT
Thread :
public TQThread
273 void msleep(
unsigned long msec);
279 unsigned int id()
const;
287 const unsigned int m_id;
289 static unsigned int sm_Id;
291 static unsigned int makeId();
296 class KDE_EXPORT
Weaver :
public TQObject
301 Weaver (TQObject* parent=0,
const char* name=0,
302 int inventoryMin = 4,
303 int inventoryMax = 32);
306 virtual void enqueue (
Job*);
315 void enqueue (TQPtrList<Job> jobs);
325 virtual bool dequeue (
Job*);
329 virtual void dequeue ();
340 virtual void finish();
351 virtual void suspend (
bool state);
353 bool isEmpty ()
const;
357 bool isIdle ()
const;
370 virtual Job* applyForWork (
Thread *thread,
Job *previous);
383 int threads ()
const;
402 void threadCreated (
Thread *);
403 void threadDestroyed (
Thread *);
404 void threadBusy (
Thread *);
405 void threadSuspended (
Thread *);
414 bool event ( TQEvent* );
450 #endif // defined WEAVER_H
int m_inventoryMin
Stored setting.
int m_active
The number of jobs that are assigned to the worker threads, but not finished.
bool m_running
m_running is set to true when a job is enqueued and set to false when the job finishes that was the l...
TQWaitCondition m_jobFinished
Wait for a job to finish.
The class Thread is used to represent the worker threads in the weaver's inventory.
A class to represent the events threads generate and send to the Weaver object.
void jobDone(Job *)
This signal is emitted when a job is done.
void suspended()
Thread queueing has been suspended.
int m_inventoryMax
Stored setting .
void done()
This signal is emitted when a job has been finished.
@ Suspended
All jobs in the queue are done.
void finished()
This signal is emitted when the Weaver has finished ALL currently queued jobs.
TQWaitCondition m_jobAvailable
Wait condition all idle or done threads wait for.
@ ThreadStarted
Thread queueing halted.
bool m_shuttingDown
Indicates if the weaver is shutting down and exiting it's threads.
TQPtrList< Thread > m_inventory
The thread inventory.
void APR()
Perform an Asynchronous Process Request.
void started()
This signal is emitted when a thread starts to process a job.
virtual void run()=0
The method that actually performs the job.
void SPR()
This signal is emitted when the job needs some operation done by the main thread (usually the creator...
TDEPIM classes for drag and drop of mails.
TQPtrList< Job > m_assignments
The job queue.
A weaver is the manager of worker threads (Thread objects) to which it assigns jobs from it's queue.
A Job is a simple abstraction of an action that is to be executed in a thread context.
bool m_suspend
If m_suspend is true, no new jobs will be assigned to threads.