diff options
Diffstat (limited to 'boost/log/detail/event.hpp')
-rw-r--r-- | boost/log/detail/event.hpp | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/boost/log/detail/event.hpp b/boost/log/detail/event.hpp index 4bb49822c1..0168e170e7 100644 --- a/boost/log/detail/event.hpp +++ b/boost/log/detail/event.hpp @@ -22,12 +22,15 @@ #ifndef BOOST_LOG_NO_THREADS #if defined(BOOST_THREAD_PLATFORM_PTHREAD) -# if defined(_POSIX_SEMAPHORES) && (_POSIX_SEMAPHORES + 0) > 0 -# if defined(__GNUC__) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) -# include <semaphore.h> -# include <boost/cstdint.hpp> -# define BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE -# endif +# include <boost/atomic/capabilities.hpp> +# if (defined(linux) || defined(__linux) || defined(__linux__)) && BOOST_ATOMIC_INT_LOCK_FREE == 2 +# include <boost/atomic/atomic.hpp> +# define BOOST_LOG_EVENT_USE_FUTEX +# elif defined(_POSIX_SEMAPHORES) && (_POSIX_SEMAPHORES + 0) > 0 && BOOST_ATOMIC_FLAG_LOCK_FREE == 2 +# include <semaphore.h> +# include <boost/cstdint.hpp> +# include <boost/atomic/atomic_flag.hpp> +# define BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE # endif #elif defined(BOOST_THREAD_PLATFORM_WIN32) # include <boost/cstdint.hpp> @@ -48,12 +51,37 @@ BOOST_LOG_OPEN_NAMESPACE namespace aux { -#if defined(BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE) +#if defined(BOOST_LOG_EVENT_USE_FUTEX) + +class futex_based_event +{ +private: + boost::atomic< int > m_state; + +public: + //! Default constructor + BOOST_LOG_API futex_based_event(); + //! Destructor + BOOST_LOG_API ~futex_based_event(); + + //! Waits for the object to become signalled + BOOST_LOG_API void wait(); + //! Sets the object to a signalled state + BOOST_LOG_API void set_signalled(); + + // Copying prohibited + BOOST_DELETED_FUNCTION(futex_based_event(futex_based_event const&)) + BOOST_DELETED_FUNCTION(futex_based_event& operator= (futex_based_event const&)) +}; + +typedef futex_based_event event; + +#elif defined(BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE) class sem_based_event { private: - boost::uint32_t m_state; + boost::atomic_flag m_state; sem_t m_semaphore; public: |