NGSolve
4.9
|
00001 #ifndef FILE_PARTHREADS 00002 #define FILE_PARTHREADS 00003 00004 this file ist not used anymore 00005 00006 00007 00008 /**************************************************************************/ 00009 /* File: parthreads.hh */ 00010 /* Author: Joachim Schoeberl */ 00011 /* Date: 22. Nov. 2000 */ 00012 /**************************************************************************/ 00013 00014 /* 00015 Parallel thread, Mutex, 00016 */ 00017 00018 #ifdef NO_PARALLEL_THREADS 00019 00020 class NgMutex { }; 00021 00022 class NgLock 00023 { 00024 public: 00025 NgLock (NgMutex & mut, bool lock = 0) { ; } 00026 void Lock () { ; } 00027 void UnLock () { ; } 00028 }; 00029 00030 00031 #else 00032 00033 #ifdef _MSC_VER 00034 # ifdef MSVC_EXPRESS 00035 // #include <pthread.h> 00036 00037 class NgMutex 00038 { 00039 pthread_mutex_t mut; 00040 public: 00041 NgMutex () 00042 { 00043 pthread_mutex_init (&mut, NULL); 00044 } 00045 friend class NgLock; 00046 }; 00047 00048 class NgLock 00049 { 00050 pthread_mutex_t & mut; 00051 bool locked; 00052 public: 00053 NgLock (NgMutex & ngmut, bool lock = false) 00054 : mut (ngmut.mut) 00055 { 00056 if (lock) 00057 pthread_mutex_lock (&mut); 00058 00059 locked = lock; 00060 }; 00061 00062 ~NgLock() 00063 { 00064 if (locked) 00065 pthread_mutex_unlock (&mut); 00066 } 00067 00068 void Lock () 00069 { 00070 pthread_mutex_lock (&mut); 00071 locked = true; 00072 } 00073 void UnLock () 00074 { 00075 pthread_mutex_unlock (&mut); 00076 locked = false; 00077 } 00078 /* 00079 int TryLock () 00080 { 00081 return pthread_mutex_trylock (&mut); 00082 } 00083 */ 00084 }; 00085 00086 # else // Using MSVC++ Standard / Professional 00087 class NgMutex 00088 { 00089 CCriticalSection cs; 00090 00091 public: 00092 NgMutex () 00093 { ; } 00094 friend class NgLock; 00095 }; 00096 00097 class NgLock 00098 { 00099 CSingleLock sl; 00100 bool locked; 00101 public: 00102 NgLock (NgMutex & mut, bool lock = 0) 00103 : sl(&mut.cs) 00104 { 00105 if (lock) sl.Lock(); 00106 locked = lock; 00107 } 00108 00109 ~NgLock () 00110 { 00111 if (locked) sl.Unlock(); 00112 } 00113 00114 void Lock () 00115 { 00116 sl.Lock(); 00117 locked = 1; 00118 } 00119 00120 void UnLock () 00121 { 00122 sl.Unlock(); 00123 locked = 0; 00124 } 00125 }; 00126 # endif // MSVC_EXPRESS 00127 00128 #else // Not using MSVC++ 00129 00130 00131 // #include <pthread.h> 00132 00133 class NgMutex 00134 { 00135 pthread_mutex_t mut; 00136 public: 00137 NgMutex () 00138 { 00139 pthread_mutex_init (&mut, NULL); 00140 } 00141 friend class NgLock; 00142 }; 00143 00144 class NgLock 00145 { 00146 pthread_mutex_t & mut; 00147 bool locked; 00148 public: 00149 NgLock (NgMutex & ngmut, bool lock = false) 00150 : mut (ngmut.mut) 00151 { 00152 if (lock) 00153 pthread_mutex_lock (&mut); 00154 00155 locked = lock; 00156 }; 00157 00158 ~NgLock() 00159 { 00160 if (locked) 00161 pthread_mutex_unlock (&mut); 00162 } 00163 00164 void Lock () 00165 { 00166 pthread_mutex_lock (&mut); 00167 locked = true; 00168 } 00169 void UnLock () 00170 { 00171 pthread_mutex_unlock (&mut); 00172 locked = false; 00173 } 00174 /* 00175 int TryLock () 00176 { 00177 return pthread_mutex_trylock (&mut); 00178 } 00179 */ 00180 }; 00181 00182 #endif // _MSC_VER 00183 00184 #endif // NO_PARALLEL_THREADS 00185 00186 #endif