ThreadWork Class Reference

#include <workthread.h>

Inheritance diagram for ThreadWork:

Inheritance graph
[legend]
List of all members.

Detailed Description

ThreadWork class indicates a job to be processed in separate thread.

Derived classes shall override pure virtual process() member function to perform their work. Notice that process() method is called from secondary thread, so everything done in that method must be multi-thread safe.

After constructing ThreadWork object on free store, wrapped in shared_ptr, submit the work to WorkThread class for processing. Only one work is being processed at any time, altough this may be changed/increased in later revisions to make better use of multi-processor systems.

Definition at line 39 of file workthread.h.


Public Member Functions

 ThreadWork ()
virtual ~ThreadWork ()
virtual bool process ()=0
 Override this pure virtual method to perform your work.
void cancel ()
 Cancels a pending job.
bool isValid ()
 Check whether this job is still valid for processing.
bool isComplete ()
 Check whether this job is complete.

Protected Member Functions

void setComplete ()
 Set the state of the job to /completed/.

Private Attributes

bool m_valid
 If true, the job is still valid.
boost::mutex m_validLock
 Protects m_valid member.
bool m_complete
 If true, the job is complete.
boost::mutex m_completeLock
 Protects m_complete member.

Constructor & Destructor Documentation

ThreadWork::ThreadWork  ) 
 

Definition at line 31 of file workthread.cpp.

ThreadWork::~ThreadWork  )  [virtual]
 

Definition at line 32 of file workthread.cpp.


Member Function Documentation

void ThreadWork::cancel  ) 
 

Cancels a pending job.

Definition at line 33 of file workthread.cpp.

References m_valid, and m_validLock.

bool ThreadWork::isComplete  ) 
 

Check whether this job is complete.

Definition at line 41 of file workthread.cpp.

References m_complete, and m_completeLock.

Referenced by HashWork::process().

bool ThreadWork::isValid  ) 
 

Check whether this job is still valid for processing.

Reimplemented in HashWork.

Definition at line 37 of file workthread.cpp.

References m_valid, and m_validLock.

virtual bool ThreadWork::process  )  [pure virtual]
 

Override this pure virtual method to perform your work.

It is highly recommended to perform your work incrementally, returning false here after each pass, and true once all the work has been processed. There is no performance penalty for doing so, and it allows us to later add support for work_progress concept.

Returns:
true if all work has been done, false otherwise.

Todo:
Return value is currently ignored by implementation; use setComplete() to indicate the job is complete to WorkThread.

Implemented in MoveWork, and HashWork.

void ThreadWork::setComplete  )  [protected]
 

Set the state of the job to /completed/.

Definition at line 45 of file workthread.cpp.

References m_complete, and m_completeLock.

Referenced by HashWork::finish(), and MoveWork::process().


Member Data Documentation

bool ThreadWork::m_complete [private]
 

If true, the job is complete.

Definition at line 70 of file workthread.h.

Referenced by isComplete(), and setComplete().

boost::mutex ThreadWork::m_completeLock [private]
 

Protects m_complete member.

Definition at line 71 of file workthread.h.

Referenced by isComplete(), and setComplete().

bool ThreadWork::m_valid [private]
 

If true, the job is still valid.

Reimplemented in HashWork.

Definition at line 68 of file workthread.h.

Referenced by cancel(), and isValid().

boost::mutex ThreadWork::m_validLock [private]
 

Protects m_valid member.

Definition at line 69 of file workthread.h.

Referenced by cancel(), and isValid().


The documentation for this class was generated from the following files: