Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

thread.h

00001 //
00002 // thread.h
00003 //
00004 // Copyright (C) 1997 Limit Point Systems, Inc.
00005 //
00006 // Author: Edward Seidl <seidl@janed.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
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     // a C linkage interface to run_Thread_run
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 
00104     virtual ThreadGrp* clone(int nthread = -1);
00105 
00106     static void set_default_threadgrp(const Ref<ThreadGrp>&);
00107     static ThreadGrp * get_default_threadgrp();
00108     static ThreadGrp * initial_threadgrp(int &argc, char ** argv);
00109 };
00110 
00111 
00115 class ProcThreadGrp: public ThreadGrp {
00116   public:
00117     ProcThreadGrp();
00118     ProcThreadGrp(const Ref<KeyVal>&);
00119     ~ProcThreadGrp();
00120 
00121     int start_threads();
00122     int wait_threads();
00123     Ref<ThreadLock> new_lock();
00124 
00125     ThreadGrp* clone(int nthread = -1);
00126 };
00127 
00128 #endif
00129 
00130 // Local Variables:
00131 // mode: c++
00132 // c-file-style: "ETS"
00133 // End:

Generated at Sat Nov 9 12:43:28 2002 for MPQC 2.0.4 using the documentation package Doxygen 1.2.15.