00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _util_group_thread_h
00029 #define _util_group_thread_h
00030
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034
00035 #include <util/class/class.h>
00036
00040 class ThreadLock : public RefCount {
00041 public:
00042 ThreadLock();
00043 virtual ~ThreadLock();
00044
00046 virtual void lock() =0;
00048 virtual void unlock() =0;
00049 };
00050
00051
00054 class Thread {
00055 public:
00056 Thread();
00057 virtual ~Thread();
00058
00059 static void *run_Thread_run(void*thread);
00060
00062 virtual void run() =0;
00063 };
00064
00065 extern "C" {
00066
00067 void *Thread__run_Thread_run(void*thread);
00068 }
00069
00072 class ThreadGrp: public DescribedClass {
00073 protected:
00074 Thread** threads_;
00075 int nthread_;
00076
00077 public:
00078 ThreadGrp();
00079 ThreadGrp(const Ref<KeyVal>&);
00080 ThreadGrp(const ThreadGrp&, int nthread = -1);
00081 virtual ~ThreadGrp();
00082
00085 void add_thread(int, Thread*);
00087 int nthread() const { return nthread_; }
00088
00089 void delete_threads();
00090
00093 virtual int start_threads() =0;
00096 virtual int wait_threads() =0;
00098 virtual Ref<ThreadLock> new_lock() =0;
00099
00105 virtual ThreadGrp* clone(int nthread = -1);
00106
00107 static void set_default_threadgrp(const Ref<ThreadGrp>&);
00108 static ThreadGrp * get_default_threadgrp();
00109 static ThreadGrp * initial_threadgrp(int &argc, char ** argv);
00110 };
00111
00112
00116 class ProcThreadGrp: public ThreadGrp {
00117 public:
00118 ProcThreadGrp();
00119 ProcThreadGrp(const Ref<KeyVal>&);
00120 ~ProcThreadGrp();
00121
00122 int start_threads();
00123 int wait_threads();
00124 Ref<ThreadLock> new_lock();
00125 };
00126
00127 #endif
00128
00129
00130
00131
00132