feisty meow concerns codebase
2.140
|
Manages a collection of threads. More...
#include <thread_cabinet.h>
Public Member Functions | |
thread_cabinet () | |
virtual | ~thread_cabinet () |
DEFINE_CLASS_NAME ("thread_cabinet") | |
structures::unique_int | add_thread (ethread *to_add, bool start_it, void *parm) |
adds a thread to be managed by the thread_cabinet. More... | |
bool | zap_thread (const structures::unique_int &to_whack) |
removes the thread with the id "to_whack". More... | |
bool | cancel_thread (const structures::unique_int &to_cancel) |
shuts down the thread "to_cancel" as quickly as possible. More... | |
int | threads () const |
number of threads being managed here. More... | |
structures::int_set | thread_ids () const |
returns the identifiers of all threads managed by this object. More... | |
bool | any_running () const |
returns true if any threads are currently running. More... | |
void | start_all (void *pointer) |
cranks up any threads that are not already running. More... | |
void | cancel_all () |
signals to all threads that they should exit as soon as possible. More... | |
void | stop_all () |
makes all of the threads quit. More... | |
ethread * | get_thread (int index) |
this returns the thread at "index" in our list. More... | |
void | clean_debris () |
clean out threads that have finished. More... | |
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 36 of file thread_cabinet.h.
processes::thread_cabinet::thread_cabinet | ( | ) |
Definition at line 64 of file thread_cabinet.cpp.
|
virtual |
Definition at line 72 of file thread_cabinet.cpp.
References basis::WHACK().
unique_int processes::thread_cabinet::add_thread | ( | ethread * | 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 81 of file thread_cabinet.cpp.
References FUNCDEF, LOCKIT, LOG, structures::roller< contents >::next_id(), processes::ethread::start(), processes::ethread::thread_finished(), and basis::WHACK().
Referenced by cromp::cromp_server::enable_servers(), and processes::post_office::register_route().
bool processes::thread_cabinet::any_running | ( | ) | const |
returns true if any threads are currently running.
Definition at line 110 of file thread_cabinet.cpp.
References LOCKIT.
void processes::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 129 of file thread_cabinet.cpp.
References continuable_error, FUNCDEF, and LOCKIT.
Referenced by stop_all().
bool processes::thread_cabinet::cancel_thread | ( | const structures::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 182 of file thread_cabinet.cpp.
References LOCKIT.
void processes::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 195 of file thread_cabinet.cpp.
References FUNCDEF, LOCKIT, and LOG.
Referenced by stop_all().
processes::thread_cabinet::DEFINE_CLASS_NAME | ( | "thread_cabinet" | ) |
ethread * processes::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 222 of file thread_cabinet.cpp.
References LOCKIT, and NULL_POINTER.
void processes::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 119 of file thread_cabinet.cpp.
References LOCKIT.
void processes::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 146 of file thread_cabinet.cpp.
References cancel_all(), clean_debris(), continuable_error, FUNCDEF, and LOCKIT.
Referenced by cromp::cromp_server::disable_servers(), and processes::post_office::stop_serving().
int_set processes::thread_cabinet::thread_ids | ( | ) | const |
returns the identifiers of all threads managed by this object.
Definition at line 213 of file thread_cabinet.cpp.
References LOCKIT.
int processes::thread_cabinet::threads | ( | ) | const |
number of threads being managed here.
Definition at line 79 of file thread_cabinet.cpp.
bool processes::thread_cabinet::zap_thread | ( | const structures::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 169 of file thread_cabinet.cpp.
References LOCKIT.
Referenced by processes::post_office::unregister_route().