#include <weaver.h>
Inherits TQObject.
A weaver is the manager of worker threads (Thread objects) to which it assigns jobs from it's queue.
Definition at line 296 of file weaver.h.
◆ applyForWork()
Job * KPIM::ThreadWeaver::Weaver::applyForWork |
( |
Thread * |
thread, |
|
|
Job * |
previous |
|
) |
| |
|
virtual |
Assign a job to the calling thread.
This is supposed to be called from the Thread objects in the inventory. Returns 0 if the weaver is shutting down, telling the calling thread to finish and exit. If no jobs are available and shut down is not in progress, the calling thread is suspended until either condition is met. In previous, threads give the job they have completed. If this is the first job, previous is zero.
Definition at line 456 of file weaver.cpp.
◆ assignJobs()
void KPIM::ThreadWeaver::Weaver::assignJobs |
( |
| ) |
|
|
protected |
Schedule enqueued jobs to be executed by idle threads.
This will try to distribute as many jobs as possible to all idle threads.
Definition at line 386 of file weaver.cpp.
◆ dequeue() [1/2]
void KPIM::ThreadWeaver::Weaver::dequeue |
( |
| ) |
|
|
virtual |
Remove all queued jobs.
Please note that this will not kill the threads, therefore all jobs that are being processed will be continued.
Definition at line 358 of file weaver.cpp.
◆ dequeue() [2/2]
bool KPIM::ThreadWeaver::Weaver::dequeue |
( |
Job * |
job | ) |
|
|
virtual |
Remove a job from the queue.
If the job qas queued but not started so far, it is simple removed from the queue. For now, it is unsupported to dequeue a job once its execution has started. For that case, you will have to provide a method to interrupt your job's execution (and receive the done signal). Returns true if the job has been dequeued, false if the job has already been started or is not found in the queue.
Definition at line 352 of file weaver.cpp.
◆ enqueue() [1/2]
void KPIM::ThreadWeaver::Weaver::enqueue |
( |
Job * |
job | ) |
|
|
virtual |
Add a job to be executed.
Definition at line 326 of file weaver.cpp.
◆ enqueue() [2/2]
void KPIM::ThreadWeaver::Weaver::enqueue |
( |
TQPtrList< Job > |
jobs | ) |
|
Enqueue all jobs in the given list.
This is an atomic operation, no jobs will start before all jobs in the list are enqueued. If you need a couple of jobs done and want to receive the finished () signal afterwards, use this method to queue them. Otherwise, when enqueueing your jobs individually, there is a chance that you receive more than one finished signal.
Definition at line 338 of file weaver.cpp.
◆ event()
bool KPIM::ThreadWeaver::Weaver::event |
( |
TQEvent * |
e | ) |
|
|
protected |
Check incoming events for user defined ones.
The threads use user defined events to communicate with the Weaver.
Definition at line 391 of file weaver.cpp.
◆ finish()
void KPIM::ThreadWeaver::Weaver::finish |
( |
| ) |
|
|
virtual |
Get notified when a thread has finished a job.
This is done automatically. Finish all queued operations, then return. This method is used in imperative programs that cannot react on events to have the controlling (main) thread wait wait for the jobs to finish. Warning: This will suspend your thread! Warning: If your jobs enter for example an infinite loop, this will never return!
Definition at line 536 of file weaver.cpp.
◆ finished
void KPIM::ThreadWeaver::Weaver::finished |
( |
| ) |
|
|
signal |
This signal is emitted when the Weaver has finished ALL currently queued jobs.
If a number of jobs is enqueued sequentially, this signal might be emitted a couple of times (what happens is that all already queued jobs have been processed while you still add new ones). This is not a bug, but the intended behaviour.
◆ isEmpty()
bool KPIM::ThreadWeaver::Weaver::isEmpty |
( |
| ) |
const |
◆ isIdle()
bool KPIM::ThreadWeaver::Weaver::isIdle |
( |
| ) |
const |
Is the weaver idle? The weaver is idle if no jobs are queued and no jobs are processed by the threads (m_active is zero).
Definition at line 530 of file weaver.cpp.
◆ jobDone
void KPIM::ThreadWeaver::Weaver::jobDone |
( |
Job * |
| ) |
|
|
signal |
This signal is emitted when a job is done.
It is up to the programmer if this signal or the done signal of the job is more handy.
◆ lock()
void KPIM::ThreadWeaver::Weaver::lock |
( |
| ) |
|
Lock the mutex for this weaver.
The threads in the inventory need to lock the weaver's mutex to synchronize the job management.
Definition at line 305 of file weaver.cpp.
◆ post()
Post an event that is handled by this object, but in the main (GUI) thread.
Different threads may use this method to communicate with the main thread. thread and job mark the objects associated with this event.
Definition at line 444 of file weaver.cpp.
◆ queueLength()
int KPIM::ThreadWeaver::Weaver::queueLength |
( |
| ) |
|
Returns the number of pending jobs.
Definition at line 524 of file weaver.cpp.
◆ suspend()
void KPIM::ThreadWeaver::Weaver::suspend |
( |
bool |
state | ) |
|
|
virtual |
Suspend job execution if state = true, otherwise resume job execution if it was suspended.
When suspending, all threads are allowed to finish the currently assigned job but will not receive a new assignment. When all threads are done processing the assigned job, the signal suspended will() be emitted. If you call suspend (true) and there are no jobs left to be done, you will immidiately receive the suspended() signal.
Definition at line 364 of file weaver.cpp.
◆ suspended
void KPIM::ThreadWeaver::Weaver::suspended |
( |
| ) |
|
|
signal |
Thread queueing has been suspended.
When suspend is called with state = true, all threads are allowed to finish their job. When the last thread finished, this signal is emitted.
◆ threads()
int KPIM::ThreadWeaver::Weaver::threads |
( |
| ) |
const |
Returns the current number of threads in the inventory.
Definition at line 320 of file weaver.cpp.
◆ unlock()
void KPIM::ThreadWeaver::Weaver::unlock |
( |
| ) |
|
◆ m_active
int KPIM::ThreadWeaver::Weaver::m_active |
|
protected |
The number of jobs that are assigned to the worker threads, but not finished.
Definition at line 421 of file weaver.h.
◆ m_assignments
TQPtrList<Job> KPIM::ThreadWeaver::Weaver::m_assignments |
|
protected |
The job queue.
Definition at line 418 of file weaver.h.
◆ m_inventory
TQPtrList<Thread> KPIM::ThreadWeaver::Weaver::m_inventory |
|
protected |
The thread inventory.
Definition at line 416 of file weaver.h.
◆ m_inventoryMax
int KPIM::ThreadWeaver::Weaver::m_inventoryMax |
|
protected |
Stored setting .
Definition at line 425 of file weaver.h.
◆ m_inventoryMin
int KPIM::ThreadWeaver::Weaver::m_inventoryMin |
|
protected |
Stored setting.
Definition at line 423 of file weaver.h.
◆ m_jobAvailable
TQWaitCondition KPIM::ThreadWeaver::Weaver::m_jobAvailable |
|
protected |
Wait condition all idle or done threads wait for.
Definition at line 427 of file weaver.h.
◆ m_jobFinished
TQWaitCondition KPIM::ThreadWeaver::Weaver::m_jobFinished |
|
protected |
Wait for a job to finish.
Definition at line 429 of file weaver.h.
◆ m_running
bool KPIM::ThreadWeaver::Weaver::m_running |
|
protected |
m_running is set to true when a job is enqueued and set to false when the job finishes that was the last in the queue.
E.g., this will flip from false to true to false when you continuously enqueue one single job.
Definition at line 437 of file weaver.h.
◆ m_shuttingDown
bool KPIM::ThreadWeaver::Weaver::m_shuttingDown |
|
protected |
Indicates if the weaver is shutting down and exiting it's threads.
Definition at line 432 of file weaver.h.
◆ m_suspend
bool KPIM::ThreadWeaver::Weaver::m_suspend |
|
protected |
If m_suspend is true, no new jobs will be assigned to threads.
Jobs may be queued, but will not be processed until suspend (false) is called.
Definition at line 442 of file weaver.h.
The documentation for this class was generated from the following files:
|