CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 #ifdef USE_JTHREADS
12 #include <juce.h> // JUCE core
13 #endif
14
15 namespace csl {
16
17 #ifdef USE_JTHREADS
18
19 /// The abstract CSL Thread class
20
21 class CThread : public juce::Thread {
22 public:
23 CThread() : juce::Thread(T("CSL Thread")) { };
24 virtual ~CThread() { };
25 static CThread * MakeThread(); ///< factory method
26
27 int createThread(VoidFcnPtr * func, void * args);
28 // int createRealtimeThread(VOIDFCNPTR * func, void * args);
29 void run();
30
31 protected:
32 VoidFcnPtr * mFunc;
33 void * mArgs;
34 };
35
36 #else // USE_JTHREADS
37
38 /// The abstract CSL Thread class
39
40 class CThread {
41 public:
42 CThread() { };
43 virtual ~CThread() { };
44 static CThread * MakeThread(); ///< factory method
45
46 virtual int createThread(VoidFcnPtr * func, void * args) = 0;
47 // virtual int createRealtimeThread(VoidFcnPtr * func, void * args) = 0;
48 };
49
50 /// Sync is a cross-thread synchronization object
51
52 class Synch {
53 public:
54 Synch() { } ///< Constructor
55 virtual ~Synch() { } ///< Destructor
56 static Synch* MakeSynch(); ///< Factory method
57 /// Utilities
58 virtual int lock() = 0;
59 virtual int unlock() = 0;
60 virtual int condWait() = 0;
61 virtual int condSignal() = 0;
62 };
63
64 #include <pthread.h> // not on Windows...
65
66 /// PThread version of Sync
67
68 class SynchPthread : public Synch {
69 public:
70 SynchPthread();
71 ~SynchPthread();
72
73 pthread_mutex_t mMutex;
74 pthread_cond_t mCond;
75
76 int lock();
77 int unlock();
78 int condWait();
79 int condSignal();
80 };
81
82 /// PThread version of Thread
83
84 class ThreadPthread : public CThread {
85 public:
86 ThreadPthread();
87 ~ThreadPthread();
88
89 pthread_t mThread;
90 pthread_attr_t mAttributes;
91
92 int createThread(VoidFcnPtr * func, void* args);
93 // int createRealtimeThread(VoidFcnPtr * func, void* args);
94 };
95
96 #endif
97
98 }
99
100 #endif