thread Class Reference

Base class for threads. More...

#include <thread.h>

Inheritance diagram for thread:
Inheritance graph
[legend]
Collaboration diagram for thread:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 thread (const string &nm)
void start (void)
virtual void run (void)
bool spawn (void)
bool runs (void)
valuenextevent (void)
valuewaitevent (void)
valuewaitevent (int timeout_msec)
void sendevent (const value &v)
void sendevent (const statstring &type)
void sendevent (const string &type)
void sendevent (const statstring &type, const value &data)
void sendevent (const char *type)
int eventqueue (void)
unsigned int threadid (void)
void setpriority (int prio)

Static Public Member Functions

static void * dorun (void *param)
static valuegetlist (void)

Public Attributes

bool finished
string threadname

Protected Attributes

pthread_t tid
pthread_attr_t attr
sched_param schedparam
bool spawned
eventq events
lock< bool > isrunning

Detailed Description

Base class for threads.

Derived classes can use this class to spawn into a background thread.


Member Function Documentation

void * thread::dorun ( void *  param  )  [static]

Static method to start thread.

Used as an argument for the system thread create.

Parameters:
param Pointer to the thread object.
Returns:
NULL (return value mandated by POSIX API).

References string::printf(), and threadname.

Referenced by spawn().

Here is the call graph for this function:

int thread::eventqueue ( void   )  [inline]

Measure the queue size.

Returns:
Number of events in the queue.

References eventq::count(), and events.

Here is the call graph for this function:

value* thread::nextevent ( void   )  [inline]

Get the next event from the queue.

The run method can call this to peek at any incoming events.

Returns:
The value object containing the event data, which may be empty.

References events, and eventq::nextevent().

Referenced by smtpworker::run(), and httpdworker::run().

Here is the call graph for this function:

bool thread::runs ( void   ) 

Check thread's running status.

Returns:
Status, true if thread runs.

References isrunning.

void thread::sendevent ( const statstring type,
const value data 
) [inline]

Send an event without data to the thread.

The receiving thread will get a value-object with a a type() set to your liking and the data from the value you supply.

Parameters:
type The event-type.
data The event data.

References events, and eventq::send().

Here is the call graph for this function:

void thread::sendevent ( const string type  )  [inline]

Send an event without data to the thread.

The receiving thread will get a value-object with a a type() set to your liking and a boolean value of 'true'.

Parameters:
type The event-type.

References events, and eventq::send().

Here is the call graph for this function:

void thread::sendevent ( const statstring type  )  [inline]

Send an event without data to the thread.

The receiving thread will get a value-object with a a type() set to your liking and a boolean value of 'true'.

Parameters:
type The event-type.

References events, and eventq::send().

Here is the call graph for this function:

void thread::sendevent ( const value v  )  [inline]

Send an event to the thread.

Other threads can call this method to dispatch commands or other events. The receiving thread will get this value with a type() of "event".

Parameters:
v The event data.

References events, and eventq::send().

Referenced by daemon::log(), httpd::shutdown(), and logthread::shutdown().

Here is the call graph for this function:

void thread::setpriority ( int  prio  )  [inline]

Set the scheduling priority.

Parameters:
prio The new priority.

References schedparam, and tid.

bool thread::spawn ( void   ) 

Spawn the thread in the background.

Exceptions:
threadCreateException Error creating a thread.

References attr, dorun(), isrunning, spawned, and tid.

Referenced by httpdworker::httpdworker(), smtpworker::smtpworker(), start(), smtpd::start(), and httpd::start().

Here is the call graph for this function:

void thread::start ( void   )  [inline]

Start the thread (alias for spawn).

Exceptions:
threadCreateException Error creating a thread.

Reimplemented in httpd, and smtpd.

References spawn().

Referenced by daemon::log().

Here is the call graph for this function:

unsigned int thread::threadid ( void   )  [inline]

Find out thread's unique id.

Returns:
The unique id number.

Referenced by smtpworker::run(), and httpdworker::run().

value* thread::waitevent ( int  timeout_msec  )  [inline]

Block waiting for an event on the queue, with timeout.

The run method can call this to wait for work.

Parameters:
timeout_msec The timeout in milliseconds.
Returns:
The value object containing the event data, which should not be empty.

References events, and eventq::waitevent().

Here is the call graph for this function:

value* thread::waitevent ( void   )  [inline]

Block waiting for an event on the queue.

The run method can call this to wait for work.

Returns:
The value object containing the event data, which should not be empty.

References events, and eventq::waitevent().

Referenced by httpd::run(), and logthread::run().

Here is the call graph for this function:


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

Generated on Sun Feb 28 10:36:58 2010 for GRACE by  doxygen 1.6.1