Structural deformable models
vuThread.h
Go to the documentation of this file.
1 /* Modified March 2002
2  By Christopher Steinbach
3  Modified to make the threads detachable so that
4  my program will stop crashing on my animations...
5 */
6 
7 #ifndef _VUTHREAD_H_
8 #define _VUTHREAD_H_
9 
10 #include <stddef.h>
11 
12 /* \todo implement vuThread and vuMutex for windows.
13 
14  information on thread wrapper classes for windows
15  http://www.codeguru.com/system/OOThreadWrapper.html
16  http://www.codeproject.com/threads/cthread.asp?print=true
17 
18 */
19 
20 class vuLock;
21 
28 class vuMutex
29 {
30  friend class vuLock;
31 public:
34  vuMutex(bool recursive=false);
37  ~vuMutex();
38 
43  void lock();
47  bool trylock();
51  void unlock();
52 
53 private:
54  void * mutex;
55 };
56 
60 class vuLock {
61 public:
63 vuLock(vuMutex &m) : lmutex(&m) {
64  lmutex->lock();
65  }
67  ~vuLock() {
68  lmutex->unlock();
69  }
70 private:
71  vuMutex *lmutex;
72 };
73 
79 class vuThread
80 {
81 public:
83  virtual ~vuThread() {};
84 
88  bool startThread(int whatsup, void* data=NULL);
89 
90 // void* retStartThread (int whatsup);
91 
95  virtual void run(int whatsup, void* data) = 0;
96 
97 // virtual void* retrun (int whatsup) {};
98 
99  void stopThread();
100 
102  static void usleep(unsigned long ms);
103 
104 protected:
105 
106 private:
107 
108 #ifdef WIN32
109  friend void _kickoff(void *ptr);
110 #else
111  friend void* _kickoff(void *ptr);
112 #endif
113  //friend void* _ret_kickoff(void *ptr);
114 
118  vuMutex m_WhatsupMutex;
119 
121  int m_Whatsup;
123  void* m_AdditionalData;
124 
125 };
126 
127 #endif
#define NULL
Definition: simpletypes.h:9
bool trylock()
Definition: vuThread.cpp:143
void * _kickoff(void *ptr)
Definition: vuThread.cpp:20
virtual ~vuThread()
Virtual destructor (doing nothing)
Definition: vuThread.h:83
~vuMutex()
Definition: vuThread.cpp:132
~vuLock()
Definition: vuThread.h:67
void unlock()
Definition: vuThread.cpp:148
vuMutex(bool recursive=false)
Definition: vuThread.cpp:117
void lock()
Definition: vuThread.cpp:138
vuLock(vuMutex &m)
Definition: vuThread.h:63