Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file detail/event.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 24.07.2011 Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_DETAIL_EVENT_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_DETAIL_EVENT_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_LOG_NO_THREADS Chris@16: Chris@16: #if defined(BOOST_THREAD_PLATFORM_PTHREAD) Chris@16: # if defined(_POSIX_SEMAPHORES) && (_POSIX_SEMAPHORES + 0) > 0 Chris@16: # if defined(__GNUC__) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) Chris@16: # include Chris@16: # include Chris@16: # define BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE Chris@16: # endif Chris@16: # endif Chris@16: #elif defined(BOOST_THREAD_PLATFORM_WIN32) Chris@16: # include Chris@16: # define BOOST_LOG_EVENT_USE_WINAPI Chris@16: #endif Chris@16: Chris@16: #if !defined(BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE) && !defined(BOOST_LOG_EVENT_USE_WINAPI) Chris@16: # include Chris@16: # include Chris@16: # define BOOST_LOG_EVENT_USE_BOOST_CONDITION Chris@16: #endif Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace aux { Chris@16: Chris@16: #if defined(BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE) Chris@16: Chris@16: class sem_based_event Chris@16: { Chris@16: private: Chris@16: boost::uint32_t m_state; Chris@16: sem_t m_semaphore; Chris@16: Chris@16: public: Chris@16: //! Default constructor Chris@16: BOOST_LOG_API sem_based_event(); Chris@16: //! Destructor Chris@16: BOOST_LOG_API ~sem_based_event(); Chris@16: Chris@16: //! Waits for the object to become signalled Chris@16: BOOST_LOG_API void wait(); Chris@16: //! Sets the object to a signalled state Chris@16: BOOST_LOG_API void set_signalled(); Chris@16: Chris@16: // Copying prohibited Chris@16: BOOST_DELETED_FUNCTION(sem_based_event(sem_based_event const&)) Chris@16: BOOST_DELETED_FUNCTION(sem_based_event& operator= (sem_based_event const&)) Chris@16: }; Chris@16: Chris@16: typedef sem_based_event event; Chris@16: Chris@16: #elif defined(BOOST_LOG_EVENT_USE_WINAPI) Chris@16: Chris@16: class winapi_based_event Chris@16: { Chris@16: private: Chris@16: boost::uint32_t m_state; Chris@16: void* m_event; Chris@16: Chris@16: public: Chris@16: //! Default constructor Chris@16: BOOST_LOG_API winapi_based_event(); Chris@16: //! Destructor Chris@16: BOOST_LOG_API ~winapi_based_event(); Chris@16: Chris@16: //! Waits for the object to become signalled Chris@16: BOOST_LOG_API void wait(); Chris@16: //! Sets the object to a signalled state Chris@16: BOOST_LOG_API void set_signalled(); Chris@16: Chris@16: // Copying prohibited Chris@16: BOOST_DELETED_FUNCTION(winapi_based_event(winapi_based_event const&)) Chris@16: BOOST_DELETED_FUNCTION(winapi_based_event& operator= (winapi_based_event const&)) Chris@16: }; Chris@16: Chris@16: typedef winapi_based_event event; Chris@16: Chris@16: #else Chris@16: Chris@16: class generic_event Chris@16: { Chris@16: private: Chris@16: boost::mutex m_mutex; Chris@16: boost::condition_variable m_cond; Chris@16: bool m_state; Chris@16: Chris@16: public: Chris@16: //! Default constructor Chris@16: BOOST_LOG_API generic_event(); Chris@16: //! Destructor Chris@16: BOOST_LOG_API ~generic_event(); Chris@16: Chris@16: //! Waits for the object to become signalled Chris@16: BOOST_LOG_API void wait(); Chris@16: //! Sets the object to a signalled state Chris@16: BOOST_LOG_API void set_signalled(); Chris@16: Chris@16: // Copying prohibited Chris@16: BOOST_DELETED_FUNCTION(generic_event(generic_event const&)) Chris@16: BOOST_DELETED_FUNCTION(generic_event& operator= (generic_event const&)) Chris@16: }; Chris@16: Chris@16: typedef generic_event event; Chris@16: Chris@16: #endif Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_NO_THREADS Chris@16: Chris@16: #endif // BOOST_LOG_DETAIL_EVENT_HPP_INCLUDED_