thread_cabinet Class Reference

Manages a collection of threads. More...

#include <thread_cabinet.h>

Collaboration diagram for thread_cabinet:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 thread_cabinet ()
virtual ~thread_cabinet ()
 IMPLEMENT_CLASS_NAME ("thread_cabinet")
unique_int add_thread (ithread *to_add, bool start_it, void *parm)
 adds a thread to be managed by the thread_cabinet.
bool zap_thread (const unique_int &to_whack)
 removes the thread with the id "to_whack".
bool cancel_thread (const unique_int &to_cancel)
 shuts down the thread "to_cancel" as quickly as possible.
int threads () const
 number of threads being managed here.
int_set thread_ids () const
 returns the identifiers of all threads managed by this object.
bool any_running () const
 returns true if any threads are currently running.
void start_all (void *pointer)
 cranks up any threads that are not already running.
void cancel_all ()
 signals to all threads that they should exit as soon as possible.
void stop_all ()
 makes all of the threads quit.
ithreadget_thread (int index)
 this returns the thread at "index" in our list.
void clean_debris ()
 clean out threads that have finished.

Detailed Description

Manages a collection of threads.

The thread cabinet allows one to corral a bunch of threads in one place and treat them as a group if necessary.

Definition at line 32 of file thread_cabinet.h.


Constructor & Destructor Documentation

thread_cabinet::thread_cabinet (  ) 

Definition at line 65 of file thread_cabinet.cpp.

thread_cabinet::~thread_cabinet (  )  [virtual]

Definition at line 73 of file thread_cabinet.cpp.

References WHACK().


Member Function Documentation

thread_cabinet::IMPLEMENT_CLASS_NAME ( "thread_cabinet"   ) 

unique_int thread_cabinet::add_thread ( ithread to_add,
bool  start_it,
void *  parm 
)

adds a thread to be managed by the thread_cabinet.

the thread cabinet takes over responsibility for the thread "to_add". if "start_it" is true, then the thread is started. otherwise it is left in whatever state it was in. the "parm" is passed to the thread's start() method.

Definition at line 82 of file thread_cabinet.cpp.

References FUNCDEF, LOCKIT, LOG, roller< contents >::next_id(), ithread::start(), ithread::thread_finished(), and WHACK().

Referenced by cromp_server::enable_servers(), and post_office::register_route().

bool thread_cabinet::zap_thread ( const unique_int to_whack  ) 

removes the thread with the id "to_whack".

if it's found and stopped and removed, true is returned. note that if the thread is found, then this will wait until the thread exits before whacking it.

Definition at line 168 of file thread_cabinet.cpp.

References LOCKIT.

Referenced by post_office::unregister_route().

bool thread_cabinet::cancel_thread ( const unique_int to_cancel  ) 

shuts down the thread "to_cancel" as quickly as possible.

this calls the cancel() method on the thread "to_cancel", which tells the thread to stop as soon as possible. once it has stopped, the clean_debris() method will throw it and other stopped threads out.

Definition at line 181 of file thread_cabinet.cpp.

References LOCKIT.

int thread_cabinet::threads (  )  const

number of threads being managed here.

Definition at line 80 of file thread_cabinet.cpp.

int_set thread_cabinet::thread_ids (  )  const

returns the identifiers of all threads managed by this object.

Definition at line 210 of file thread_cabinet.cpp.

References LOCKIT.

bool thread_cabinet::any_running (  )  const

returns true if any threads are currently running.

Definition at line 109 of file thread_cabinet.cpp.

References LOCKIT.

void thread_cabinet::start_all ( void *  pointer  ) 

cranks up any threads that are not already running.

the "pointer" will be provided to any threads that are started.

Definition at line 118 of file thread_cabinet.cpp.

References LOCKIT.

void thread_cabinet::cancel_all (  ) 

signals to all threads that they should exit as soon as possible.

this does not actually wait for them to exit.

Definition at line 128 of file thread_cabinet.cpp.

References class_name, continuable_error, FUNCDEF, and LOCKIT.

Referenced by stop_all().

void thread_cabinet::stop_all (  ) 

makes all of the threads quit.

they are cleaned up after they have stopped running also. any attempts to add threads while this method is operating will be rejected.

Definition at line 145 of file thread_cabinet.cpp.

References cancel_all(), class_name, clean_debris(), continuable_error, FUNCDEF, LOCKIT, and portable::sleep_ms().

Referenced by cromp_server::disable_servers(), and post_office::stop_serving().

ithread * thread_cabinet::get_thread ( int  index  ) 

this returns the thread at "index" in our list.

note that this is not safe to use if other threads could be removing threads from the cabinet or calling clean_debris().

Definition at line 219 of file thread_cabinet.cpp.

References LOCKIT, and NIL.

void thread_cabinet::clean_debris (  ) 

clean out threads that have finished.

note that if threads were added to the list without starting them, then these get cleaned out also.

Definition at line 194 of file thread_cabinet.cpp.

References FUNCDEF, LOCKIT, and LOG.

Referenced by stop_all().


The documentation for this class was generated from the following files:
Generated on Fri Nov 28 04:31:03 2008 for HOOPLE Libraries by  doxygen 1.5.1