• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

ThreadWeaver

  • ThreadWeaver
  • WeaverInterface
Signals | Public Member Functions | List of all members
ThreadWeaver::WeaverInterface Class Referenceabstract

#include <WeaverInterface.h>

Inheritance diagram for ThreadWeaver::WeaverInterface:
Inheritance graph
[legend]

Signals

void finished ()
 
void jobDone (ThreadWeaver::Job *)
 
void stateChanged (ThreadWeaver::State *)
 
void suspended ()
 

Public Member Functions

 WeaverInterface (QObject *parent=0)
 
virtual ~WeaverInterface ()
 
virtual int currentNumberOfThreads () const =0
 
virtual bool dequeue (Job *)=0
 
virtual void dequeue ()=0
 
virtual void enqueue (Job *)=0
 
virtual void finish ()=0
 
virtual bool isEmpty () const =0
 
virtual bool isIdle () const =0
 
virtual int maximumNumberOfThreads () const =0
 
virtual int queueLength () const =0
 
virtual void registerObserver (WeaverObserver *)=0
 
virtual void requestAbort ()=0
 
virtual void resume ()=0
 
virtual void setMaximumNumberOfThreads (int cap)=0
 
virtual const State & state () const =0
 
virtual void suspend ()=0
 

Detailed Description

WeaverInterface provides a common interface for weaver implementations.

In most cases, it is sufficient for an application to hold exactly one ThreadWeaver job queue. To execute jobs in a specific order, use job dependencies. To limit the number of jobs of a certain type that can be executed at the same time, use resource restrictions. To handle special requirements of the application when it comes to the order of execution of jobs, implement a special queue policy and apply it to the jobs.

Users of the ThreadWeaver API are encouraged to program to this interface, instead of the implementation. This way, implementation changes will not affect user programs.

This interface can be used for example to implement adapters and decorators. The member documentation is provided in the Weaver and WeaverImpl classes.

Definition at line 61 of file WeaverInterface.h.

Constructor & Destructor Documentation

WeaverInterface::WeaverInterface ( QObject *  parent = 0)
explicit

A ThreadWeaver object manages a queue of Jobs.

It inherits QObject.

Definition at line 33 of file WeaverInterface.cpp.

virtual ThreadWeaver::WeaverInterface::~WeaverInterface ( )
inlinevirtual

Definition at line 69 of file WeaverInterface.h.

Member Function Documentation

virtual int ThreadWeaver::WeaverInterface::currentNumberOfThreads ( ) const
pure virtual

Returns the current number of threads in the inventory.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

virtual bool ThreadWeaver::WeaverInterface::dequeue ( Job *  )
pure virtual

Remove a job from the queue.

If the job was queued but not started so far, it is simply 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.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

virtual void ThreadWeaver::WeaverInterface::dequeue ( )
pure virtual

Remove all queued jobs.

Please note that this will not kill the threads, therefore all jobs that are being processed will be continued.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

virtual void ThreadWeaver::WeaverInterface::enqueue ( Job *  )
pure virtual

Add a job to be executed.

It depends on the state if execution of the job will be attempted immediately. In suspended state, jobs can be added to the queue, but the threads remain suspended. In WorkongHard state, an idle thread may immediately execute the job, or it might be queued if all threads are busy.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

virtual void ThreadWeaver::WeaverInterface::finish ( )
pure virtual

Finish all queued operations, then return.

This method is used in imperative (not event driven) programs that cannot react on events to have the controlling (main) thread wait wait for the jobs to finish. The call will block the calling thread and return when all queued jobs have been processed.

Warning: This will suspend your thread! Warning: If one of your jobs enters an infinite loop, this will never return!

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

void ThreadWeaver::WeaverInterface::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.

virtual bool ThreadWeaver::WeaverInterface::isEmpty ( ) const
pure virtual

Is the queue empty? The queue is empty if no more jobs are queued.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

virtual bool ThreadWeaver::WeaverInterface::isIdle ( ) const
pure virtual

Is the weaver idle? The weaver is idle if no jobs are queued and no jobs are processed by the threads.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

void ThreadWeaver::WeaverInterface::jobDone ( ThreadWeaver::Job *  )
signal

This signal is emitted when a job is finished.

In addition, the Job itself emits a done() signal just before the jobDone() signal is emitted.

virtual int ThreadWeaver::WeaverInterface::maximumNumberOfThreads ( ) const
pure virtual

Get the maximum number of threads this Weaver may start.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

virtual int ThreadWeaver::WeaverInterface::queueLength ( ) const
pure virtual

Returns the number of pending jobs.

This will return the number of queued jobs. Jobs that are currently being executed are not part of the queue. All jobs in the queue are waiting to be executed.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

virtual void ThreadWeaver::WeaverInterface::registerObserver ( WeaverObserver *  )
pure virtual

Register an observer.

Observers provides signals on different weaver events that are otherwise only available through objects of different classes (threads, jobs). Usually, access to the signals of those objects is not provided through the weaver API. Use an observer to reveice notice, for example, on thread activity.

To unregister, simply delete the observer.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

virtual void ThreadWeaver::WeaverInterface::requestAbort ( )
pure virtual

Request aborts of the currently executed jobs.

It is important to understand that aborts are requested, but cannot be guaranteed, as not all Job classes support it. It is up to the application to decide if and how job aborts are necessary.

Implemented in ThreadWeaver::WeaverImpl, and ThreadWeaver::Weaver.

virtual void ThreadWeaver::WeaverInterface::resume ( )
pure virtual

Resume job queueing.

See also
suspend

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

virtual void ThreadWeaver::WeaverInterface::setMaximumNumberOfThreads ( int  cap)
pure virtual

Set the maximum number of threads this Weaver object may start.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

virtual const State& ThreadWeaver::WeaverInterface::state ( ) const
pure virtual

Return the state of the weaver object.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

void ThreadWeaver::WeaverInterface::stateChanged ( ThreadWeaver::State *  )
signal

The Weaver's state has changed.

virtual void ThreadWeaver::WeaverInterface::suspend ( )
pure virtual

Suspend job execution.

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() and there are no jobs left to be done, you will immediately receive the suspended() signal.

Implemented in ThreadWeaver::Weaver, and ThreadWeaver::WeaverImpl.

void ThreadWeaver::WeaverInterface::suspended ( )
signal

Thread queueing has been suspended.

When suspend is called with, all threads are allowed to finish their job. When the last thread finished, this signal is emitted.


The documentation for this class was generated from the following files:
  • WeaverInterface.h
  • WeaverInterface.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ThreadWeaver

Skip menu "ThreadWeaver"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal