/** * @file include/ActivMiddleware/ActivBase/PrivateMutexFactory.h * * @brief Header file for the private mutex factory class. */ #if (!defined ACTIV_BASE_PRIVATE_MUTEX_FACTORY_H) #define ACTIV_BASE_PRIVATE_MUTEX_FACTORY_H #include "ActivMiddleware/ActivBase/External.h" #include "ActivMiddleware/ActivBase/IMutex.h" #include "ActivMiddleware/Misc/Singleton.h" //! Activ namespace. namespace Activ { /** * @brief Private mutex factory class. * * A private mutex cannot be shared across process boundaries. * * Mutexes will, by default, be recursive. This can be overridden by setting the ACTIV_NON_RECURSIVE_MUTEX environment * variable (to any value). This is a first step to switching to non-recursive mutexes. * * On Posix, the environment variable ACTIV_COUNT_MUTEX_CONTENTION can be used to hackily count mutex contentions. * It should only be used for temporary profiling, as it will incur a small performance hit. * Windows always counts mutex contentions. */ class PrivateMutexFactory : public Singleton { public: /** * @brief Create a mutex. * * @param isInitialOwner whether the mutex is initially locked on creation. * * @return pointer to an object providing an IMutex interface. * * @throw Exception. */ ACTIV_BASE_API IMutex *Create(const bool isInitialOwner = false); /** * @brief Get a reference to the singleton instance. * * @return Reference. */ ACTIV_BASE_API static PrivateMutexFactory &GetInstance(); private: /** * @brief Constructor. */ ACTIV_BASE_API PrivateMutexFactory(); /** * @brief Destructor. */ ACTIV_BASE_API ~PrivateMutexFactory(); /** * @brief Create a mutex. * * @param isInitialOwner whether the mutex is initially locked on creation. * * @return pointer to an object providing an IMutex interface. * * @throw Exception. */ template IMutex *InternalCreate(const bool isInitialOwner); const bool m_isRecursive; ///< default is recursive unless overridden by ACTIV_NON_RECURSIVE_MUTEX env var const bool m_shouldCountContention; ///< ignored on Windows (always counts); default false on Posix friend class Singleton; }; } // namespace Activ #endif // (!defined ACTIV_BASE_PRIVATE_MUTEX_FACTORY_H)