CSL  6.0
ThreadUtilities.h
Go to the documentation of this file.
1 //
2 // ThreadUtilities.h -- cross-platform Thread Utilities
3 //
4 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
5 //
6 
7 #ifndef CSL_ThreadUtilities_H
8 #define CSL_ThreadUtilities_H
9 
10 #include "CSL_Types.h"
11 
12 #ifdef USE_JTHREADS
13  #include "JuceHeader.h" // JUCE core
14 #else
15  #include <pthread.h>
16 #endif
17 
18 namespace csl {
19 
20 #ifdef USE_JTHREADS
21 
22 /// The JUCE CSL Thread class
23 
24 class CThread : public juce::Thread {
25 public:
26  CThread() : juce::Thread("CSL Thread") { };
27  virtual ~CThread() { };
28  static CThread * MakeThread(); ///< factory method
29 
30  int (VoidFcnPtr * func, void * args);
31 // int createRealtimeThread(VOIDFCNPTR * func, void * args);
32  void run();
33 
34 protected:
35  VoidFcnPtr * mFunc;
36  void * mArgs;
37 };
38 
39 #else // USE_PTHREADS
40 
41 /// The PThreads CSL Thread class
42 
43 class CThread {
44 public:
45  CThread();
46  virtual ~CThread();
47  static CThread * MakeThread(); ///< factory method
48 
49  virtual int createThread(VoidFcnPtr * func, void * args) = 0;
50 // virtual int createRealtimeThread(VoidFcnPtr * func, void * args) = 0;
51  void stopThread (int timeOutMilliseconds);
52 
53  pthread_t mThread;
54  pthread_attr_t mAttributes;
55 
56 };
57 
58 /// Sync is a cross-thread synchronization object
59 
60 class Synch {
61 public:
62  Synch() { } ///< Constructor
63  virtual ~Synch() { } ///< Destructor
64  static Synch* MakeSynch(); ///< Factory method
65  /// Utilities
66  virtual int lock() = 0;
67  virtual int unlock() = 0;
68  virtual int condWait() = 0;
69  virtual int condSignal() = 0;
70 };
71 
72 #include <pthread.h> // not on Windows...
73 
74 /// PThread version of Sync
75 
76 class SynchPthread : public Synch {
77 public:
78  SynchPthread();
79  ~SynchPthread();
80 
81  pthread_mutex_t mMutex;
82  pthread_cond_t mCond;
83 
84  int lock();
85  int unlock();
86  int condWait();
87  int condSignal();
88 };
89 
90 /// PThread version of Thread
91 
92 class ThreadPthread : public CThread {
93 public:
94  ThreadPthread();
96 
97  int createThread(VoidFcnPtr * func, void* args);
98 // int createRealtimeThread(VoidFcnPtr * func, void* args);
99 };
100 
101 #endif
102 
103 }
104 
105 #endif
The PThreads CSL Thread class.
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
pthread_attr_t mAttributes
PThread version of Sync.
static Synch * MakeSynch()
Factory method Utilities.
Sync is a cross-thread synchronization object.
virtual int condWait()=0
pthread_mutex_t mMutex
virtual ~Synch()
Destructor.
pthread_t mThread
void stopThread(int timeOutMilliseconds)
void * VoidFcnPtr(void *arg)
the generic void fcn pointer
Definition: CSL_Types.h:221
virtual ~CThread()
PThread version of Thread.
Synch()
Constructor.
virtual int unlock()=0
virtual int createThread(VoidFcnPtr *func, void *args)=0
virtual int lock()=0
static CThread * MakeThread()
factory method
virtual int condSignal()=0
int createThread(VoidFcnPtr *func, void *args)
pthread_cond_t mCond