26 #include <tqptrlist.h>
28 #include <tqwaitcondition.h>
32 #include <tdemacros.h>
35 namespace ThreadWeaver {
53 TDE_EXPORT extern bool Debug;
54 TDE_EXPORT extern int DebugLevel;
56 TDE_EXPORT inline void setDebugLevel ( bool debug, int level)
62 TDE_EXPORT inline void debug( int severity, const char * cformat, ...)
64 __attribute__ ( (format (printf, 2, 3 ) ) )
68 TDE_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 TDE_EXPORT Event : public TQCustomEvent
123 Action action () const;
128 static const int Type;
163 class TDE_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 TDE_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 TDE_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* );
A class to represent the events threads generate and send to the Weaver object.
@ Suspended All jobs in the queue are done.
@ ThreadStarted Thread queueing halted.
A Job is a simple abstraction of an action that is to be executed in a thread context.
void SPR() This signal is emitted when the job needs some operation done by the main thread (usually the creator...
virtual void run()=0 The method that actually performs the job.
void APR() Perform an Asynchronous Process Request.
void started() This signal is emitted when a thread starts to process a job.
void done() This signal is emitted when a job has been finished.
The class Thread is used to represent the worker threads in the weaver's inventory.
A weaver is the manager of worker threads (Thread objects) to which it assigns jobs from it's queue.
void jobDone(Job *) This signal is emitted when a job is done.
bool m_suspend If m_suspend is true, no new jobs will be assigned to threads.
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_jobAvailable Wait condition all idle or done threads wait for.
int m_inventoryMax Stored setting .
int m_inventoryMin Stored setting.
int m_active The number of jobs that are assigned to the worker threads, but not finished.
TQWaitCondition m_jobFinished Wait for a job to finish.
bool m_shuttingDown Indicates if the weaver is shutting down and exiting it's threads.
TQPtrList< Job > m_assignments The job queue.
void finished() This signal is emitted when the Weaver has finished ALL currently queued jobs.
TQPtrList< Thread > m_inventory The thread inventory.
void suspended() Thread queueing has been suspended.
TDEPIM classes for drag and drop of mails.
|