diff --git a/openssl-act-engine/src/SyncObject.h b/openssl-act-engine/src/SyncObject.h index e6ca779..9d84491 100644 --- a/openssl-act-engine/src/SyncObject.h +++ b/openssl-act-engine/src/SyncObject.h @@ -1,184 +1,184 @@ -////////////////////////////////////////////////////////////////////////// -// Name: SyncObject.h -// Product: cv act library -// Purpose: Multithreading synchronization primitive for multiple Operating Systems. -// -// Copyright: (c) 2009 cv cryptovision GmbH -// all rights reserved -// Licence: The conditions for the use of this software are regulated -// in the cv act library licence agreement. -// -// Autor: Markus Tesche -// Date: 04/23/2009 -////////////////////////////////////////////////////////////////////////// - -#ifndef SyncObject_h -#define SyncObject_h - -#include "actBasics.h" - -#if defined(ACT_WIN32_WCE) -# include "SyncObjectWinCE.h" - -#elif defined(ACT_WIN32) -# include "SyncObjectWin32.h" - -#elif defined(ACT_SOLARIS) -# include "SyncObjectSloaris.h" - -#elif defined(ACT_MACOSX) -# include "SyncObjectMacOS.h" - -// posix has always to be last checked ! -#elif defined(ACT_POSIX) -# include "SyncObjectPosix.h" - -#else -# error SyncObject not implemented for this system - -#endif - -#include "actHandle.h" -#include "actISynchronize.h" - -namespace act -{ - // - // Synchronizeable<> - template - < - typename BaseT, /* ISynchronize or derived */ - typename SyncObjectT = SyncObject - > - class Synchronizeable : public BaseT - { - public: - typedef SyncObjectT SyncObject; - typedef ValueHandle SyncHandle; - - protected: - // - // ISynchronize methods - virtual void Lock() { syncObject().lock(); } - virtual void Unlock() { syncObject().unlock(); } - virtual long LockCount() const { return syncObject().lockCount(); } - - virtual const Handle& syncHandle() const { return m_sync_handle; } - - protected: - SyncObjectT& syncObject() const { return m_sync_handle.valueRef(); } - - protected: - ValueHandle m_sync_handle; - }; - - // - // GuardT<> - template - < - class SyncObjectT, - class BaseT = void, - class TypeT = void - > - class GuardT; - - // - // GuardT<> - template - class GuardT - { - public: - typedef SyncObjectT SyncObject; - - private: - GuardT(const GuardT&); - GuardT& operator=(const GuardT&); - - public: - GuardT(SyncObjectT& sync_object) - : m_sync_object(sync_object) - { - m_sync_object.lock(); - } - - GuardT(const Handle& sync_handle) - : m_sync_object(sync_handle.requiredAs()) - { - m_sync_object.lock(); - } - - GuardT(const ValueHandle& sync_handle) - : m_sync_object(sync_handle.valueRef()) - { - m_sync_object.lock(); - } - - ~GuardT() - { - m_sync_object.unlock(); - } - - long LockCount() const { return m_sync_object.lockCount(); } - - protected: - SyncObjectT& m_sync_object; - }; - - // - // GuardT<> - template - class GuardT - { - public: - typedef SyncObjectT SyncObject; - - private: - GuardT(const GuardT&); - GuardT& operator=(const GuardT&); - - public: - GuardT(ISynchronize& synchronize) - : m_guard(synchronize.syncHandle()) - { } - - GuardT(const ISynchronize& synchronize) - : m_guard(synchronize.syncHandle()) - { } - - long LockCount() const { return m_guard.LockCount(); } - - protected: - GuardT m_guard; - }; - - // - // GuardT<> - template - class GuardT - : public GuardT - { - public: - GuardT(TypeT& synchronize) - : GuardT(synchronize) - , m_synchronized(synchronize) - { } - - TypeT* operator->() const { return &m_synchronized; } - - protected: - TypeT& m_synchronized; - }; - - - typedef GuardT Guard; - typedef GuardT Synchronize; - - template - GuardT Synchronized(TypeT& synchronize) - { - return GuardT(synchronize); - } - -} // namespace act - -#endif // SyncObject_h +////////////////////////////////////////////////////////////////////////// +// Name: SyncObject.h +// Product: cv act library +// Purpose: Multithreading synchronization primitive for multiple Operating Systems. +// +// Copyright: (c) 2009 cv cryptovision GmbH +// all rights reserved +// Licence: The conditions for the use of this software are regulated +// in the cv act library licence agreement. +// +// Autor: Markus Tesche +// Date: 04/23/2009 +////////////////////////////////////////////////////////////////////////// + +#ifndef SyncObject_h +#define SyncObject_h + +#include "actBasics.h" + +#if defined(ACT_WIN32_WCE) +# include "SyncObjectWinCE.h" + +#elif defined(ACT_WIN32) +# include "SyncObjectWin32.h" + +#elif defined(ACT_SOLARIS) +# include "SyncObjectSloaris.h" + +#elif defined(ACT_MACOSX) +# include "SyncObjectMacOS.h" + +// posix has always to be last checked ! +#elif defined(ACT_POSIX) +# include "SyncObjectPosix.h" + +#else +# error SyncObject not implemented for this system + +#endif + +#include "actHandle.h" +#include "actISynchronize.h" + +namespace act +{ + // + // Synchronizeable<> + template + < + typename BaseT, /* ISynchronize or derived */ + typename SyncObjectT = SyncObject + > + class Synchronizeable : public BaseT + { + public: + typedef SyncObjectT SyncObject; + typedef ValueHandle SyncHandle; + + protected: + // + // ISynchronize methods + virtual void Lock() { syncObject().lock(); } + virtual void Unlock() { syncObject().unlock(); } + virtual long LockCount() const { return syncObject().lockCount(); } + + virtual const Handle& syncHandle() const { return m_sync_handle; } + + protected: + SyncObjectT& syncObject() const { return m_sync_handle.valueRef(); } + + protected: + ValueHandle m_sync_handle; + }; + + // + // GuardT<> + template + < + class SyncObjectT, + class BaseT = void, + class TypeT = void + > + class GuardT; + + // + // GuardT<> + template + class GuardT + { + public: + typedef SyncObjectT SyncObject; + + private: + GuardT(const GuardT&); + GuardT& operator=(const GuardT&); + + public: + GuardT(SyncObjectT& sync_object) + : m_sync_object(sync_object) + { + m_sync_object.lock(); + } + + GuardT(const Handle& sync_handle) + : m_sync_object(sync_handle.requiredAs()) + { + m_sync_object.lock(); + } + + GuardT(const ValueHandle& sync_handle) + : m_sync_object(sync_handle.valueRef()) + { + m_sync_object.lock(); + } + + virtual ~GuardT() + { + m_sync_object.unlock(); + } + + long LockCount() const { return m_sync_object.lockCount(); } + + protected: + SyncObjectT& m_sync_object; + }; + + // + // GuardT<> + template + class GuardT + { + public: + typedef SyncObjectT SyncObject; + + private: + GuardT(const GuardT&); + GuardT& operator=(const GuardT&); + + public: + GuardT(ISynchronize& synchronize) + : m_guard(synchronize.syncHandle()) + { } + + GuardT(const ISynchronize& synchronize) + : m_guard(synchronize.syncHandle()) + { } + + long LockCount() const { return m_guard.LockCount(); } + + protected: + GuardT m_guard; + }; + + // + // GuardT<> + template + class GuardT + : public GuardT + { + public: + GuardT(TypeT& synchronize) + : GuardT(synchronize) + , m_synchronized(synchronize) + { } + + TypeT* operator->() const { return &m_synchronized; } + + protected: + TypeT& m_synchronized; + }; + + + typedef GuardT Guard; + typedef GuardT Synchronize; + + template + GuardT Synchronized(TypeT& synchronize) + { + return GuardT(synchronize); + } + +} // namespace act + +#endif // SyncObject_h