feisty meow concerns codebase  2.140
thread_cabinet.h
Go to the documentation of this file.
1 #ifndef THREAD_CABINET_CLASS
2 #define THREAD_CABINET_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : thread_cabinet *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2000-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 // forward.
19 #include "ethread.h"
20 
21 #include <basis/mutex.h>
22 #include <structures/roller.h>
23 #include <structures/set.h>
24 #include <structures/unique_id.h>
25 
26 namespace processes {
27 
28 class thread_amorph;
29 
31 
37 {
38 public:
40  virtual ~thread_cabinet();
41 
42  DEFINE_CLASS_NAME("thread_cabinet");
43 
44  structures::unique_int add_thread(ethread *to_add, bool start_it, void *parm);
46 
51  bool zap_thread(const structures::unique_int &to_whack);
53 
57  bool cancel_thread(const structures::unique_int &to_cancel);
59 
63  int threads() const;
64 
67 
68  bool any_running() const;
70 
71  void start_all(void *pointer);
73 
75  void cancel_all();
77 
79  void stop_all();
81 
84  ethread *get_thread(int index);
86 
89  void clean_debris();
91 
94 private:
95  basis::mutex *_lock;
96  thread_amorph *_threads;
97  structures::int_roller *_next_id;
98  int _no_additions;
99 };
100 
101 } //namespace.
102 
103 #endif
104 
Provides a platform-independent object for adding threads to a program.
Definition: ethread.h:36
Manages a collection of threads.
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.
void clean_debris()
clean out threads that have finished.
int threads() const
number of threads being managed here.
DEFINE_CLASS_NAME("thread_cabinet")
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.
Definition: roller.h:79
A simple object that wraps a templated set of ints.
Definition: set.h:156
A unique identifier based on integers.
Definition: unique_id.h:97