Dv::Thread::Pool::Thread Class Reference

Base class for threads that can be kept in a Dv::Thread::Pool. More...

#include <pool.h>

Inheritance diagram for Dv::Thread::Pool::Thread:
Inheritance graph
[legend]
Collaboration diagram for Dv::Thread::Pool::Thread:
Collaboration graph
[legend]

List of all members.

Classes

struct  Init
 Auxiliary class which is used to support thread specific initialization and finalization. More...

Public Member Functions

 Thread (Pool &pool)
 Constructor.
virtual ~Thread ()
 Destructor.
virtual void work ()=0
 Do some work.
virtual void setup_for_work ()=0
 Set up this thread for work.
int main ()
 Main function of the thread.

Protected Member Functions

virtual Init::shared_ptr init () const
 Function that creates a shared pointer to a (class derived from) Init object.

Private Types

enum  { WORK = 0 }

Private Member Functions

void setup ()
 Set up this thread with input for work.
bool wait ()
 Wait for the WORK condition to be signaled.
void signal ()
 Signal the WORK condition.

Private Attributes

Monitor monitor_
Poolpool_

Friends

class Pool
class Init

Detailed Description

Base class for threads that can be kept in a Dv::Thread::Pool.

See also:
Dv::Thread::Pool::Factory::create
Dv::Thread::Pool::Factory::create
Examples:

test-pool.C.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
WORK 

Constructor & Destructor Documentation

Dv::Thread::Pool::Thread::Thread ( Pool pool  ) 

Constructor.

Parameters:
pool to which the thread belongs
virtual Dv::Thread::Pool::Thread::~Thread (  )  [virtual]

Destructor.

Reimplemented from Dv::Thread::Thread.


Member Function Documentation

virtual void Dv::Thread::Pool::Thread::work (  )  [pure virtual]

Do some work.

This function is called by Dv::Thread::Pool::Thread::main whenever the thread is selected by Dv::Thread::Pool::delegate.

Warning:
if the function implements a loop, it should check for killed() and exit the function as soon as killed() is detected.
See also:
Dv::Thread::Pool::~Pool
virtual void Dv::Thread::Pool::Thread::setup_for_work (  )  [pure virtual]

Set up this thread for work.

Typically, this would fill in some input data, e.g. by grabbing them from the Thread factory (see test-pool.C in the distribution for an example).

int Dv::Thread::Pool::Thread::main (  )  [virtual]

Main function of the thread.

Returns:
1 iff an exception was raised by Thread::work
0 otherwise

Reimplemented from Dv::Thread::Thread.

virtual Init::shared_ptr Dv::Thread::Pool::Thread::init (  )  const [inline, protected, virtual]

Function that creates a shared pointer to a (class derived from) Init object.

See also:
Dv::Thread::Thread::Init
void Dv::Thread::Pool::Thread::setup (  )  [private]

Set up this thread with input for work.

This function grabs the monitor and calls Dv::Pool::Thread::setup_for_work

See also:
Dv::Pool::Thread::setup_for_work
Dv::Pool::delegate
bool Dv::Thread::Pool::Thread::wait (  )  [inline, private]

Wait for the WORK condition to be signaled.

Returns:
true iff the WORK condition was actually signaled
false if the wait timed out (after 1 second).

Reimplemented from Dv::Thread::Thread.

References monitor_, Dv::Thread::Monitor::wait(), and WORK.

void Dv::Thread::Pool::Thread::signal (  )  [inline, private]

Signal the WORK condition.

This function should not be called by the Thread itself.

See also:
Dv::Thread::Pool::delegate

References monitor_, Dv::Thread::Monitor::signal(), and WORK.


Friends And Related Function Documentation

friend class Pool [friend]
friend class Init [friend]

Member Data Documentation

Referenced by signal(), and wait().


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

dvthread-0.13.4 [11 December, 2009]