24 #define LOCKIT auto_synchronizer l(*_lock)
28 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
33 using namespace basis;
46 thread_record(
const unique_int &
id, ethread *t)
47 : _thread(t), _id(
id) {}
57 class thread_amorph :
public amorph<thread_record>
64 thread_cabinet::thread_cabinet()
66 _threads(new thread_amorph),
84 #ifdef DEBUG_THREAD_CABINET
89 #ifdef DEBUG_THREAD_CABINET
90 LOG(
"no additions flag is true; destroying the thread and failing out.");
96 int use_id = _next_id->
next_id();
100 #ifdef DEBUG_THREAD_CABINET
102 LOG(
a_sprintf(
"thread %x is not going to be started and it "
103 "hasn't started yet!", to_add));
106 _threads->append(
new thread_record(use_id, to_add));
113 for (
int i = 0; i < _threads->elements(); i++) {
114 if (_threads->borrow(i)->_thread->thread_started())
return true;
122 for (
int i = 0; i < _threads->elements(); i++) {
123 if (_threads->borrow(i)->_thread->thread_finished()) {
124 _threads->borrow(i)->_thread->start(ptr);
135 for (
int i = 0; i < _threads->elements(); i++) {
136 _threads->borrow(i)->_thread->cancel();
141 if (_no_additions < 0)
155 time_control::sleep_ms(20);
158 if (!_threads->elements())
break;
160 time_control::sleep_ms(20);
164 if (_no_additions < 0)
172 for (
int i = 0; i < _threads->elements(); i++) {
173 if (_threads->borrow(i)->_id == to_whack) {
185 for (
int i = 0; i < _threads->elements(); i++) {
186 if (_threads->borrow(i)->_id == to_cancel) {
188 _threads->borrow(i)->_thread->cancel();
197 #ifdef DEBUG_THREAD_CABINET
201 for (
int i = 0; i < _threads->elements(); i++) {
202 if (_threads->borrow(i)->_thread->thread_finished()) {
204 #ifdef DEBUG_THREAD_CABINET
205 LOG(
a_sprintf(
"clearing thread %x out.", _threads->borrow(i)->_thread));
217 for (
int i = 0; i < _threads->elements(); i++)
218 to_return += _threads->borrow(i)->_id.raw_id();
225 thread_record *rec = _threads->borrow(index);
226 if (rec)
return rec->_thread;
a_sprintf is a specialization of astring that provides printf style support.
Provides a platform-independent object for adding threads to a program.
bool start(void *thread_data)
causes the thread to start, if it has not already been started.
bool thread_finished() const
returns true if the thread has exited.
bool cancel_thread(const structures::unique_int &to_cancel)
shuts down the thread "to_cancel" as quickly as possible.
bool any_running() const
returns true if any threads are currently running.
bool zap_thread(const structures::unique_int &to_whack)
removes the thread with the id "to_whack".
structures::unique_int add_thread(ethread *to_add, bool start_it, void *parm)
adds a thread to be managed by the thread_cabinet.
void start_all(void *pointer)
cranks up any threads that are not already running.
structures::int_set thread_ids() const
returns the identifiers of all threads managed by this object.
void cancel_all()
signals to all threads that they should exit as soon as possible.
virtual ~thread_cabinet()
void clean_debris()
clean out threads that have finished.
int threads() const
number of threads being managed here.
ethread * get_thread(int index)
this returns the thread at "index" in our list.
void stop_all()
makes all of the threads quit.
A roller that's based on integers. This is the most common type so far.
A simple object that wraps a templated set of ints.
contents next_id()
returns a unique (per instance of this type) id.
A unique identifier based on integers.
#define continuable_error(c, f, i)
#define NULL_POINTER
The value representing a pointer to nothing.
#define MAXINT32
Maximum 32-bit integer value.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.