Back to home page

EIC code displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // Copyright (c) Lewis Baker
0003 // Licenced under MIT license. See LICENSE.txt for details.
0004 ///////////////////////////////////////////////////////////////////////////////
0005 #ifndef CPPCORO_SYNC_WAIT_HPP_INCLUDED
0006 #define CPPCORO_SYNC_WAIT_HPP_INCLUDED
0007 
0008 #include <cppcoro/detail/lightweight_manual_reset_event.hpp>
0009 #include <cppcoro/detail/sync_wait_task.hpp>
0010 #include <cppcoro/awaitable_traits.hpp>
0011 
0012 #include <cstdint>
0013 #include <atomic>
0014 
0015 namespace cppcoro
0016 {
0017     template<typename AWAITABLE>
0018     auto sync_wait(AWAITABLE&& awaitable)
0019         -> typename cppcoro::awaitable_traits<AWAITABLE&&>::await_result_t
0020     {
0021 #if CPPCORO_COMPILER_MSVC && CPPCORO_COMPILER_MSVC < 19'20'00000
0022         // HACK: Need to explicitly specify template argument to make_sync_wait_task
0023         // here to work around a bug in MSVC when passing parameters by universal
0024         // reference to a coroutine which causes the compiler to think it needs to
0025         // 'move' parameters passed by rvalue reference.
0026         auto task = detail::make_sync_wait_task<AWAITABLE>(awaitable);
0027 #else
0028         auto task = detail::make_sync_wait_task(std::forward<AWAITABLE>(awaitable));
0029 #endif
0030         detail::lightweight_manual_reset_event event;
0031         task.start(event);
0032         event.wait();
0033         return task.result();
0034     }
0035 }
0036 
0037 #endif