ThreadUtilities.h

Go to the documentation of this file.
00001 //
00002 //  ThreadUtilities.h -- cross-platform Thread Utilities
00003 //      We should rewrite this to use JUCE threads, like soon
00004 //
00005 //  See the copyright notice and acknowledgment of authors in the file COPYRIGHT
00006 //
00007 
00008 #ifndef CSL_ThreadUtilities_H
00009 #define CSL_ThreadUtilities_H
00010 
00011 #include "CSL_Types.h"
00012 
00013 namespace csl {
00014 
00015 typedef void* (*ThreadFunc)(void*);     
00016 
00020 class Synch {
00021 public:
00022     Synch() { }                 
00023     virtual ~Synch() { }        
00024     static Synch* MakeSynch();  
00025 
00026     virtual int lock() = 0;
00027     virtual int unlock() = 0;
00028     virtual int condWait() = 0;
00029     virtual int condSignal() = 0;
00030 };
00031 
00035 class Thread {
00036 public:
00037     Thread() { }
00038     virtual ~Thread() { }
00039     static Thread* MakeThread();    
00040 
00041     virtual int createThread(ThreadFunc func, void * args) = 0;
00042     virtual int createRealtimeThread(ThreadFunc func, void * args) = 0;
00043 };
00044 
00045 #include <pthread.h>        // not on Wondows...
00046 
00050 class SynchPthread : public Synch {
00051 public:
00052     SynchPthread();
00053     ~SynchPthread();
00054 
00055     pthread_mutex_t mMutex;
00056     pthread_cond_t mCond;
00057 
00058     int lock();
00059     int unlock();
00060     int condWait();
00061     int condSignal();
00062 };
00063 
00067 class ThreadPthread : public Thread {
00068 public:
00069     ThreadPthread();
00070     ~ThreadPthread();
00071 
00072     pthread_t mThread;
00073     pthread_attr_t mAttributes;
00074 
00075     int createThread(ThreadFunc func, void* args);  
00076     int createRealtimeThread(ThreadFunc func, void* args);  
00077 };
00078 
00079 }
00080 
00081 #endif

Generated on Thu Sep 17 23:14:16 2009 for CSL by  doxygen 1.5.8