00001 // 00002 // ThreadUtilities.h -- cross-platform Thread Utilities 00003 // 00004 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT 00005 // 00006 00007 #ifndef CSL_ThreadUtilities_H 00008 #define CSL_ThreadUtilities_H 00009 00010 #include "CSL_Types.h" 00011 #include "juce.h" // JUCE core 00012 00013 namespace csl { 00014 00015 #ifdef USE_JTHREADS 00016 00018 00019 class CThread : public juce::Thread { 00020 public: 00021 CThread() : juce::Thread(T("CSL Thread")) { }; 00022 virtual ~CThread() { }; 00023 static CThread * MakeThread(); 00024 00025 int createThread(VOIDFCNPTR * func, void * args); 00026 // int createRealtimeThread(VOIDFCNPTR * func, void * args); 00027 void run(); 00028 00029 protected: 00030 VOIDFCNPTR * mFunc; 00031 void * mArgs; 00032 }; 00033 00034 #else // USE_JTHREADS 00035 00037 00038 class CThread { 00039 public: 00040 CThread() { }; 00041 virtual ~CThread() { }; 00042 static CThread * MakeThread(); 00043 00044 virtual int createThread(VOIDFCNPTR * func, void * args) = 0; 00045 // virtual int createRealtimeThread(VOIDFCNPTR * func, void * args) = 0; 00046 }; 00047 00049 00050 class Synch { 00051 public: 00052 Synch() { } 00053 virtual ~Synch() { } 00054 static Synch* MakeSynch(); 00055 00056 virtual int lock() = 0; 00057 virtual int unlock() = 0; 00058 virtual int condWait() = 0; 00059 virtual int condSignal() = 0; 00060 }; 00061 00062 #include <pthread.h> // not on Windows... 00063 00065 00066 class SynchPthread : public Synch { 00067 public: 00068 SynchPthread(); 00069 ~SynchPthread(); 00070 00071 pthread_mutex_t mMutex; 00072 pthread_cond_t mCond; 00073 00074 int lock(); 00075 int unlock(); 00076 int condWait(); 00077 int condSignal(); 00078 }; 00079 00081 00082 class ThreadPthread : public CThread { 00083 public: 00084 ThreadPthread(); 00085 ~ThreadPthread(); 00086 00087 pthread_t mThread; 00088 pthread_attr_t mAttributes; 00089 00090 int createThread(VOIDFCNPTR * func, void* args); 00091 // int createRealtimeThread(VOIDFCNPTR * func, void* args); 00092 }; 00093 00094 #endif 00095 00096 } 00097 00098 #endif
1.4.5-20051010