OpenWalnut 1.2.5
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions

WThreadedRunner Class Reference

Base class for all classes needing to be executed in a separate thread. More...

#include <WThreadedRunner.h>

Inheritance diagram for WThreadedRunner:

List of all members.

Public Types

typedef boost::function< void(void) > THREADFUNCTION
 Type used for simple thread functions.

Public Member Functions

 WThreadedRunner ()
 Default constructor.
virtual ~WThreadedRunner ()
 Destructor.
virtual void run ()
 Run thread.
void run (THREADFUNCTION f)
 Run thread.
void wait (bool requestFinish=false)
 Wait for the thread to be finished.
virtual void requestStop ()
 This method's purpose is to request a stop without waiting for it.

Protected Member Functions

virtual void threadMain ()
 Function that has to be overwritten for execution.
virtual void notifyStop ()
 Gets called when the thread should be stopped.
void yield () const
 Give remaining execution timeslice to another thread.
void sleep (const int32_t t) const
 Sets thread asleep.
void msleep (const int32_t t) const
 Sets thread asleep.
void waitForStop ()
 Let the thread sleep until a stop request was given.

Protected Attributes

boost::thread m_thread
 Thread instance.
WBoolFlag m_shutdownFlag
 Condition getting fired whenever the thread should quit.

Private Member Functions

 WThreadedRunner (const WThreadedRunner &rhs)
 Disallow copy construction.
WThreadedRunneroperator= (const WThreadedRunner &rhs)
 Disallow copy assignment.

Detailed Description

Base class for all classes needing to be executed in a separate thread.

Definition at line 41 of file WThreadedRunner.h.


Member Typedef Documentation

typedef boost::function< void ( void ) > WThreadedRunner::THREADFUNCTION

Type used for simple thread functions.

Definition at line 48 of file WThreadedRunner.h.


Constructor & Destructor Documentation

WThreadedRunner::WThreadedRunner ( )

Default constructor.

Definition at line 33 of file WThreadedRunner.cpp.

WThreadedRunner::~WThreadedRunner ( ) [virtual]

Destructor.

Definition at line 39 of file WThreadedRunner.cpp.

WThreadedRunner::WThreadedRunner ( const WThreadedRunner rhs) [private]

Disallow copy construction.

Parameters:
rhsthe other threaded runner.

Member Function Documentation

void WThreadedRunner::msleep ( const int32_t  t) const [protected]

Sets thread asleep.

Parameters:
ttime to sleep in microseconds.

Definition at line 98 of file WThreadedRunner.cpp.

References sleep().

void WThreadedRunner::notifyStop ( ) [protected, virtual]

Gets called when the thread should be stopped.

The purpose of this method is to allow derived classes to handle this kind of event.

Reimplemented in WGraphicsEngine.

Definition at line 84 of file WThreadedRunner.cpp.

Referenced by requestStop().

WThreadedRunner& WThreadedRunner::operator= ( const WThreadedRunner rhs) [private]

Disallow copy assignment.

Parameters:
rhsthe other threaded runner.
Returns:
this.
void WThreadedRunner::requestStop ( ) [virtual]

This method's purpose is to request a stop without waiting for it.

Definition at line 65 of file WThreadedRunner.cpp.

References m_shutdownFlag, and notifyStop().

Referenced by WModuleContainer::moduleError(), WWorkerThreadTest::testStopThread(), and wait().

void WThreadedRunner::run ( ) [virtual]
void WThreadedRunner::run ( THREADFUNCTION  f)

Run thread.

This does not start threadMain(() but runs a specified function instead.

Parameters:
fthe function to run instead of the threadMain method.

Definition at line 51 of file WThreadedRunner.cpp.

References m_thread.

void WThreadedRunner::sleep ( const int32_t  t) const [protected]

Sets thread asleep.

Parameters:
ttime to sleep in seconds.

Definition at line 93 of file WThreadedRunner.cpp.

Referenced by WModuleImpl::moduleMain(), msleep(), WThreadedRunnerTest::testSleep(), and WThreadedRunnerImpl::threadMain().

void WThreadedRunner::threadMain ( ) [protected, virtual]

Function that has to be overwritten for execution.

It gets executed in a separate thread after run() has been called.

Reimplemented in WThreadedRunnerImpl, WWorkerThread< Function_T >, WCreateColorArraysThread, WGraphicsEngine, WBatchLoader, WKdTreeThread, WKernel, WModule, WModuleCombiner, and WProjectFile.

Definition at line 79 of file WThreadedRunner.cpp.

References WLogger::addLogMessage(), and WLogger::getLogger().

Referenced by run().

void WThreadedRunner::wait ( bool  requestFinish = false)

Wait for the thread to be finished.

Parameters:
requestFinishtrue if the thread should be notified.

Definition at line 56 of file WThreadedRunner.cpp.

References m_thread, and requestStop().

Referenced by WDataSetFibers::init(), WWorkerThreadTest::testExceptions(), WWorkerThreadTest::testMultipleThreads(), WThreadedRunnerTest::testRun(), WWorkerThreadTest::testSingleThread(), WWorkerThreadTest::testStopThread(), and WKdTree::WKdTree().

void WThreadedRunner::waitForStop ( ) [protected]

Let the thread sleep until a stop request was given.

Definition at line 74 of file WThreadedRunner.cpp.

References m_shutdownFlag, and WFlag< T >::wait().

Referenced by WKernel::threadMain().

void WThreadedRunner::yield ( ) const [protected]

Give remaining execution timeslice to another thread.

Definition at line 88 of file WThreadedRunner.cpp.

References m_thread.


Member Data Documentation

Condition getting fired whenever the thread should quit.

This is useful for waiting for stop requests.

Definition at line 129 of file WThreadedRunner.h.

Referenced by WKernel::isFinishRequested(), WModuleImpl::moduleMain(), requestStop(), WThreadedRunnerImpl::threadMain(), waitForStop(), and WModule::WModule().

boost::thread WThreadedRunner::m_thread [protected]

Thread instance.

Definition at line 100 of file WThreadedRunner.h.

Referenced by run(), wait(), and yield().


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends