OnixS C++ FIX Engine 2.79.1.0
C:/Users/Pasha/_Dev/fixforge-cpp/fix/cppEngine/include/OnixS/FIX/Threading.h
00001 /*
00002 * Copyright 2005-2011 Onix Solutions Limited [OnixS]. All rights reserved. 
00003 * 
00004 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law 
00005 * and international copyright treaties. 
00006 * 
00007 * Access to and use of the software is governed by the terms of the applicable ONIXS Software
00008 * Services Agreement (the Agreement) and Customer end user license agreements granting 
00009 * a non-assignable, non-transferable and non-exclusive license to use the software 
00010 * for it's own data processing purposes under the terms defined in the Agreement.
00011 * 
00012 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part 
00013 * of this source code or associated reference material to any other location for further reproduction
00014 * or redistribution, and any amendments to this copyright notice, are expressly prohibited. 
00015 *
00016 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with 
00017 * the terms of the Agreement is a violation of copyright law. 
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             // Implementation details.
00067             void* impl_;
00068 
00069             // Copying & assignment is prohibited.
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             // Implementation details.
00109             void* impl_;
00110 
00111             // Copying & assignment is prohibited.
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             // Implementation details.
00142             void* impl_;
00143 
00144             // Copying & assignment is prohibited.
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         // Aliases for guards for known synchronization objects.
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             // No instances of current thread are avaiable.
00189             ThisThread(const ThisThread&);
00190             ThisThread& operator =(const ThisThread&);
00191         };
00192     }
00193 }
00194 
00195 #endif // __ONIXS_FIXENGINE_THREADING_H__