Classes | Public Member Functions | Protected Member Functions | Protected Attributes

RakNet::FunctionThread Class Reference

#include <FunctionThread.h>

Collaboration diagram for RakNet::FunctionThread:
Collaboration graph
[legend]

List of all members.

Classes

struct  FunctorAndContext

Public Member Functions

 FunctionThread ()
 ~FunctionThread ()
void StartThreads (int numThreads)
 Starts the thread up.
void StopThreads (bool blockOnCurrentProcessing)
 Stop processing.
void Push (Functor *functor, void *context=0)
 Add a functor to the incoming stream of functors.
void CallResultHandlers (void)
 Call FunctorResultHandler callbacks.
void CancelFunctorsWithContext (bool(*cancelThisFunctor)(FunctorAndContext func, void *userData), void *userData)
 If you want to cancel input and output functors associated with some context, you can pass a function to do that here.
void SetPostResultFunction (void(*postResult)(FunctorAndContext func))
 If you want to automatically do some kind of processing on every functor after Functor::HandleResult is called, set it here.

Protected Member Functions

void CancelInput (void)

Protected Attributes

ThreadPool< FunctorAndContext,
FunctorAndContext
threadPool
void(* pr )(FunctorAndContext func)

Detailed Description

FunctionThread takes a stream of classes that implement a processing function, processes them in a thread, and calls a callback with the result. It's a useful way to call blocking functions that you do not want to block, such as file writes and database operations.

Definition at line 25 of file FunctionThread.h.


Constructor & Destructor Documentation

FunctionThread::FunctionThread (  ) 

Definition at line 21 of file FunctionThread.cpp.

FunctionThread::~FunctionThread (  ) 

Definition at line 25 of file FunctionThread.cpp.

Here is the call graph for this function:


Member Function Documentation

void FunctionThread::CallResultHandlers ( void   ) 

Call FunctorResultHandler callbacks.

Normally you would call this once per update cycle, although you do not have to.

Definition at line 51 of file FunctionThread.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void FunctionThread::CancelFunctorsWithContext ( bool(*)(FunctorAndContext func, void *userData)  cancelThisFunctor,
void *  userData 
)

If you want to cancel input and output functors associated with some context, you can pass a function to do that here.

Parameters:
[in] cancelThisFunctor Function should return true to cancel the functor, false to let it process
[in] userData Pointer to whatever you want. Passed to the cancelThisFunctor call

Definition at line 61 of file FunctionThread.cpp.

Here is the call graph for this function:

void FunctionThread::CancelInput ( void   )  [protected]

Definition at line 82 of file FunctionThread.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void FunctionThread::Push ( Functor functor,
void *  context = 0 
)

Add a functor to the incoming stream of functors.

Note:
functor MUST be a valid pointer until Functor::HandleResult() is called, at which point the pointer is returned to you.
For practical purposes this means the instance of functor you pass to this function has to be allocated using new and delete.
You should deallocate the pointer inside Functor::HandleResult()
Parameters:
[in] functor A pointer to an implemented Functor class
[in] If there is some context to this functor you want to look up to cancel it, you can set it here. Returned back to you in Functor::HandleResult

Definition at line 44 of file FunctionThread.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void FunctionThread::SetPostResultFunction ( void(*)(FunctorAndContext func)  postResult  ) 

If you want to automatically do some kind of processing on every functor after Functor::HandleResult is called, set it here.

Useful to cleanup FunctionThread::Push::context

Parameters:
[in] postResult pointer to a C function to do post-processing

Definition at line 78 of file FunctionThread.cpp.

void FunctionThread::StartThreads ( int  numThreads  ) 

Starts the thread up.

Definition at line 29 of file FunctionThread.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void FunctionThread::StopThreads ( bool  blockOnCurrentProcessing  ) 

Stop processing.

Will also call FunctorResultHandler callbacks with /a wasCancelled set to true.

Parameters:
[in] blockOnCurrentProcessing Wait for the current processing to finish?

Definition at line 33 of file FunctionThread.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

void(* RakNet::FunctionThread::pr)(FunctorAndContext func) [protected]

Definition at line 72 of file FunctionThread.h.

Definition at line 70 of file FunctionThread.h.


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