00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #if !defined(__ONIXS_FIXENGINE_THREADING_H__)
00021 #define __ONIXS_FIXENGINE_THREADING_H__
00022
00023 #include "OnixS/FIX/ABI.h"
00024
00025 namespace OnixS
00026 {
00027 namespace Threading
00028 {
00037 class ONIXS_FIXENGINE_API Mutex
00038 {
00039 public:
00040 friend ONIXS_FIXENGINE_API_DECL(class, Condition);
00041
00043 Mutex();
00044
00046 ~Mutex();
00047
00052 void acquire();
00053
00059 bool tryAcquire();
00060
00063 void release();
00064
00065 private:
00066
00067 void* impl_;
00068
00069
00070
00071 Mutex(const Mutex&);
00072 Mutex& operator =(const Mutex&);
00073 };
00074
00077 class ONIXS_FIXENGINE_API Semaphore
00078 {
00079 public:
00085 Semaphore(unsigned int count = 1);
00086
00088 ~Semaphore();
00089
00094 void acquire();
00095
00100 bool tryAcquire();
00101
00105 void release();
00106
00107 private:
00108
00109 void* impl_;
00110
00111
00112
00113 Semaphore(const Semaphore&);
00114 Semaphore& operator =(const Semaphore&);
00115 };
00116
00120 class ONIXS_FIXENGINE_API Condition
00121 {
00122 public:
00126 Condition(Mutex& lock);
00127
00129 ~Condition();
00130
00132 void signal();
00133
00135 void signalAll();
00136
00138 void wait();
00139
00140 private:
00141
00142 void* impl_;
00143
00144
00145
00146 Condition(const Condition&);
00147 Condition& operator =(const Condition&);
00148 };
00149
00151 template<class Acquirable> class Guard
00152 {
00153 public:
00155 Guard(Acquirable& acquirable)
00156 : acquirable_(acquirable)
00157 {
00158 acquirable_.acquire();
00159 }
00160
00162 ~Guard()
00163 {
00164 acquirable_.release();
00165 }
00166
00167 private:
00168 Acquirable& acquirable_;
00169
00170 Guard(const Guard&);
00171 Guard& operator =(const Guard&);
00172 };
00173
00174
00175
00176 typedef Guard<Mutex> MutexGuard;
00177 typedef Guard<Semaphore> SemaphoreGuard;
00178
00180 class ONIXS_FIXENGINE_API ThisThread
00181 {
00182 public:
00185 static void sleep(unsigned int milliseconds);
00186
00187 private:
00188
00189 ThisThread(const ThisThread&);
00190 ThisThread& operator =(const ThisThread&);
00191 };
00192 }
00193 }
00194
00195 #endif // __ONIXS_FIXENGINE_THREADING_H__