NGSolve  5.3
parthreads.hpp
1 #ifndef FILE_PARTHREADS
2 #define FILE_PARTHREADS
3 
4 this file ist not used anymore
5 
6 
7 
8 /**************************************************************************/
9 /* File: parthreads.hh */
10 /* Author: Joachim Schoeberl */
11 /* Date: 22. Nov. 2000 */
12 /**************************************************************************/
13 
14 /*
15  Parallel thread, Mutex,
16 */
17 
18 #ifdef NO_PARALLEL_THREADS
19 
20 class NgMutex { };
21 
22 class NgLock
23 {
24 public:
25  NgLock (NgMutex & mut, bool lock = 0) { ; }
26  void Lock () { ; }
27  void UnLock () { ; }
28 };
29 
30 
31 #else
32 
33 #ifdef _MSC_VER
34 # ifdef MSVC_EXPRESS
35 // #include <pthread.h>
36 
37 class NgMutex
38 {
39  pthread_mutex_t mut;
40 public:
41  NgMutex ()
42  {
43  pthread_mutex_init (&mut, NULL);
44  }
45  friend class NgLock;
46 };
47 
48 class NgLock
49 {
50  pthread_mutex_t & mut;
51  bool locked;
52 public:
53  NgLock (NgMutex & ngmut, bool lock = false)
54  : mut (ngmut.mut)
55  {
56  if (lock)
57  pthread_mutex_lock (&mut);
58 
59  locked = lock;
60  };
61 
62  ~NgLock()
63  {
64  if (locked)
65  pthread_mutex_unlock (&mut);
66  }
67 
68  void Lock ()
69  {
70  pthread_mutex_lock (&mut);
71  locked = true;
72  }
73  void UnLock ()
74  {
75  pthread_mutex_unlock (&mut);
76  locked = false;
77  }
78  /*
79  int TryLock ()
80  {
81  return pthread_mutex_trylock (&mut);
82  }
83  */
84 };
85 
86 # else // Using MSVC++ Standard / Professional
87 class NgMutex
88 {
89  CCriticalSection cs;
90 
91 public:
92  NgMutex ()
93  { ; }
94  friend class NgLock;
95 };
96 
97 class NgLock
98 {
99  CSingleLock sl;
100  bool locked;
101 public:
102  NgLock (NgMutex & mut, bool lock = 0)
103  : sl(&mut.cs)
104  {
105  if (lock) sl.Lock();
106  locked = lock;
107  }
108 
109  ~NgLock ()
110  {
111  if (locked) sl.Unlock();
112  }
113 
114  void Lock ()
115  {
116  sl.Lock();
117  locked = 1;
118  }
119 
120  void UnLock ()
121  {
122  sl.Unlock();
123  locked = 0;
124  }
125 };
126 # endif // MSVC_EXPRESS
127 
128 #else // Not using MSVC++
129 
130 
131 // #include <pthread.h>
132 
133 class NgMutex
134 {
135  pthread_mutex_t mut;
136 public:
137  NgMutex ()
138  {
139  pthread_mutex_init (&mut, NULL);
140  }
141  friend class NgLock;
142 };
143 
144 class NgLock
145 {
146  pthread_mutex_t & mut;
147  bool locked;
148 public:
149  NgLock (NgMutex & ngmut, bool lock = false)
150  : mut (ngmut.mut)
151  {
152  if (lock)
153  pthread_mutex_lock (&mut);
154 
155  locked = lock;
156  };
157 
158  ~NgLock()
159  {
160  if (locked)
161  pthread_mutex_unlock (&mut);
162  }
163 
164  void Lock ()
165  {
166  pthread_mutex_lock (&mut);
167  locked = true;
168  }
169  void UnLock ()
170  {
171  pthread_mutex_unlock (&mut);
172  locked = false;
173  }
174  /*
175  int TryLock ()
176  {
177  return pthread_mutex_trylock (&mut);
178  }
179  */
180 };
181 
182 #endif // _MSC_VER
183 
184 #endif // NO_PARALLEL_THREADS
185 
186 #endif
Definition: parthreads.hpp:133
Definition: parthreads.hpp:144