Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Thread.H

00001 /* $Id: Thread.H,v 1.2 2000/11/03 22:03:28 rpav Exp $
00002  *
00003  * SFW - Studio FrameWork
00004  * Copyright (C) 2000  Ryan Pavlik
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019  *
00020  */
00021 
00022 #ifndef THREAD_H
00023 #define THREAD_H
00024 
00025 #include "Object.H"
00026 
00027 namespace SFW {
00028 
00029 #include <pthread.h>
00030 
00031     /*
00032      * class Thread
00033      *
00034      * This is for making new threads. Subclass and override proc().
00035      *
00036      */
00037 
00038     class Thread : public Object {
00039     pthread_t pt;
00040     bool isDetached;
00041 
00042     protected:
00043     void enableCancel();
00044     void disableCancel();
00045         void testCancel();
00046         void exit();
00047     
00048     public:
00049     V_TYPE_INFO(SFW::Thread, SFW::Object);
00050     
00051     Thread(void);
00052     virtual ~Thread() { };
00053 
00054     // Thread operations
00055     void run   (void);
00056     void detach(void);
00057     void join  (void);
00058     void cancel(void);
00059     
00060     // The actual thread procedure
00061     virtual void main(void)  = 0;
00062     };
00063 
00064     enum MutexType {
00065     QUICK, RECURSIVE, ERROR_CHECKING
00066     };
00067     
00068     /*
00069      * class Mutex
00070      *
00071      * This is for locking. Make a new one and use lock() and unlock()
00072      *
00073      */
00074     class Mutex : public Object {
00075     protected:                  // CHECK: this is hackish atm
00076     pthread_mutex_t mutex;
00077 
00078     public:
00079         TYPE_INFO(SFW::Mutex, SFW::Object);
00080         
00081     Mutex(MutexType t = RECURSIVE);
00082     ~Mutex();
00083 
00084     void lock   (void);
00085     void unlock (void);
00086     bool trylock(void);
00087     };
00088 
00089 
00090     /*
00091      * class Condition
00092      *
00093      * This is for signalling conditions. Make one and use
00094      * wait(), signal(), and broadcast().
00095      *
00096      */
00097     enum ShouldLock {
00098         DO_LOCK, ALREADY_LOCKED
00099     };
00100 
00101     class Condition : public Mutex {
00102     protected:
00103     pthread_cond_t cond;
00104 
00105     public:
00106         TYPE_INFO(SFW::Condition, SFW::Mutex);
00107         
00108     Condition(void);
00109     ~Condition();
00110 
00111     void wait     (ShouldLock = DO_LOCK);
00112     void signal   (ShouldLock = DO_LOCK);
00113     void broadcast(ShouldLock = DO_LOCK);
00114     };
00115 }
00116 
00117 #endif /* THREAD_H */

Generated at Tue Jan 2 15:38:34 2001 for SFW by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000