Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:50

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // Copyright (c) Lewis Baker
0003 // Licenced under MIT license. See LICENSE.txt for details.
0004 ///////////////////////////////////////////////////////////////////////////////
0005 #ifndef CPPCORO_DETAIL_LIGHTWEIGHT_MANUAL_RESET_EVENT_HPP_INCLUDED
0006 #define CPPCORO_DETAIL_LIGHTWEIGHT_MANUAL_RESET_EVENT_HPP_INCLUDED
0007 
0008 #include <cppcoro/config.hpp>
0009 
0010 #if CPPCORO_OS_LINUX || (CPPCORO_OS_WINNT >= 0x0602)
0011 # include <atomic>
0012 # include <cstdint>
0013 #elif CPPCORO_OS_WINNT
0014 # include <cppcoro/detail/win32.hpp>
0015 #else
0016 # include <mutex>
0017 # include <condition_variable>
0018 #endif
0019 
0020 namespace cppcoro
0021 {
0022     namespace detail
0023     {
0024         class lightweight_manual_reset_event
0025         {
0026         public:
0027 
0028             lightweight_manual_reset_event(bool initiallySet = false);
0029 
0030             ~lightweight_manual_reset_event();
0031 
0032             void set() noexcept;
0033 
0034             void reset() noexcept;
0035 
0036             void wait() noexcept;
0037 
0038         private:
0039 
0040 #if CPPCORO_OS_LINUX
0041             std::atomic<int> m_value;
0042 #elif CPPCORO_OS_WINNT >= 0x0602
0043             // Windows 8 or newer we can use WaitOnAddress()
0044             std::atomic<std::uint8_t> m_value;
0045 #elif CPPCORO_OS_WINNT
0046             // Before Windows 8 we need to use a WIN32 manual reset event.
0047             cppcoro::detail::win32::handle_t m_eventHandle;
0048 #else
0049             // For other platforms that don't have a native futex
0050             // or manual reset event we can just use a std::mutex
0051             // and std::condition_variable to perform the wait.
0052             // Not so lightweight, but should be portable to all platforms.
0053             std::mutex m_mutex;
0054             std::condition_variable m_cv;
0055             bool m_isSet;
0056 #endif
0057         };
0058     }
0059 }
0060 
0061 #endif