Skip to content

Commit

Permalink
msvc warning fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Oct 18, 2023
1 parent 3a1eda4 commit 0ff2d4e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
10 changes: 7 additions & 3 deletions include/boost/cobalt/detail/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,21 @@ auto get_resume_result(Awaitable & aw) -> system::result<decltype(aw.await_resum
}

#if BOOST_COBALT_NO_SELF_DELETE
BOOST_COBALT_DECL void self_destroy(std::coroutine_handle<void> h, const cobalt::executor & exec) noexcept;

BOOST_COBALT_DECL
void self_destroy(std::coroutine_handle<void> h, const cobalt::executor & exec) noexcept;

template<typename T>
BOOST_COBALT_DECL void self_destroy(std::coroutine_handle<T> h) noexcept
inline void self_destroy(std::coroutine_handle<T> h) noexcept
{
if constexpr (requires {h.promise().get_executor();})
self_destroy(h, h.promise().get_executor());
else
self_destroy(h, this_thread::get_executor());
}


#else

template<typename T>
inline void self_destroy(std::coroutine_handle<T> h) noexcept
{
Expand All @@ -144,6 +147,7 @@ inline void self_destroy(std::coroutine_handle<T> h, const Executor &) noexcept
{
h.destroy();
}

#endif

template<typename T>
Expand Down
12 changes: 6 additions & 6 deletions include/boost/cobalt/this_coro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ void *allocate_coroutine(const std::size_t size, AllocatorType alloc_)
using alloc_type = typename std::allocator_traits<AllocatorType>::template rebind_alloc<unsigned char>;
alloc_type alloc{alloc_};

const auto align_needed = size % alignof(alloc_type);
const auto align_offset = align_needed != 0 ? alignof(alloc_type) - align_needed : 0ull;
const auto alloc_size = size + sizeof(alloc_type) + align_offset;
const std::size_t align_needed = size % alignof(alloc_type);
const std::size_t align_offset = align_needed != 0 ? alignof(alloc_type) - align_needed : 0ull;
const std::size_t alloc_size = size + sizeof(alloc_type) + align_offset;
const auto raw = std::allocator_traits<alloc_type>::allocate(alloc, alloc_size);
new(raw + size + align_offset) alloc_type(std::move(alloc));

Expand All @@ -379,9 +379,9 @@ void deallocate_coroutine(void *raw_, const std::size_t size)
using alloc_type = typename std::allocator_traits<AllocatorType>::template rebind_alloc<unsigned char>;
const auto raw = static_cast<unsigned char *>(raw_);

const auto align_needed = size % alignof(alloc_type);
const auto align_offset = align_needed != 0 ? alignof(alloc_type) - align_needed : 0ull;
const auto alloc_size = size + sizeof(alloc_type) + align_offset;
const std::size_t align_needed = size % alignof(alloc_type);
const std::size_t align_offset = align_needed != 0 ? alignof(alloc_type) - align_needed : 0ull;
const std::size_t alloc_size = size + sizeof(alloc_type) + align_offset;
auto alloc_p = reinterpret_cast<alloc_type *>(raw + size + align_offset);

auto alloc = std::move(*alloc_p);
Expand Down
5 changes: 3 additions & 2 deletions test/gather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

using namespace boost;

static cobalt::promise<std::size_t> wdummy(asio::any_io_executor exec,
static cobalt::promise<std::chrono::milliseconds::rep> wdummy(
asio::any_io_executor exec,
std::chrono::milliseconds ms = std::chrono::milliseconds(25))
{
if (ms == std::chrono::milliseconds ::max())
Expand Down Expand Up @@ -74,7 +75,7 @@ CO_TEST_CASE("variadic")
CO_TEST_CASE("list")
{
auto exec = co_await asio::this_coro::executor;
std::vector<cobalt::promise<std::size_t>> vec;
std::vector<cobalt::promise<std::chrono::milliseconds::rep>> vec;
vec.push_back(wdummy(exec, std::chrono::milliseconds(100)));
vec.push_back(wdummy(exec, std::chrono::milliseconds( 50)));
vec.push_back(wdummy(exec, std::chrono::milliseconds(150)));
Expand Down
5 changes: 3 additions & 2 deletions test/join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

using namespace boost;

static cobalt::promise<std::size_t> wdummy(asio::any_io_executor exec,
static cobalt::promise<std::chrono::milliseconds::rep> wdummy(
asio::any_io_executor exec,
std::chrono::milliseconds ms = std::chrono::milliseconds(25))
{
if (ms == std::chrono::milliseconds ::max())
Expand Down Expand Up @@ -84,7 +85,7 @@ CO_TEST_CASE("variadic-throw")
CO_TEST_CASE("list")
{
auto exec = co_await asio::this_coro::executor;
std::vector<cobalt::promise<std::size_t>> vec;
std::vector<cobalt::promise<std::chrono::milliseconds::rep>> vec;
vec.push_back(wdummy(exec, std::chrono::milliseconds(100)));
vec.push_back(wdummy(exec, std::chrono::milliseconds( 50)));
vec.push_back(wdummy(exec, std::chrono::milliseconds(150)));
Expand Down
5 changes: 3 additions & 2 deletions test/left_race.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
using namespace boost;


static cobalt::promise<std::size_t> dummy(asio::any_io_executor exec,
static cobalt::promise<std::chrono::milliseconds::rep> dummy(
asio::any_io_executor exec,
std::chrono::milliseconds ms = std::chrono::milliseconds(50))
{
asio::steady_timer tim{exec, ms};
Expand Down Expand Up @@ -61,7 +62,7 @@ CO_TEST_CASE("variadic")
CO_TEST_CASE("list")
{
auto exec = co_await asio::this_coro::executor;
std::vector<cobalt::promise<std::size_t>> vec;
std::vector<cobalt::promise<std::chrono::milliseconds::rep>> vec;
vec.push_back(dummy(exec, std::chrono::milliseconds(100)));
vec.push_back(dummy(exec, std::chrono::milliseconds( 50)));
vec.push_back(dummy(exec, std::chrono::milliseconds(100000)));
Expand Down
12 changes: 7 additions & 5 deletions test/race.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
using namespace boost;


static cobalt::promise<std::size_t> dummy(asio::any_io_executor exec,
static cobalt::promise<std::chrono::milliseconds::rep> dummy(
asio::any_io_executor exec,
std::chrono::milliseconds ms = std::chrono::milliseconds(50))
{
asio::steady_timer tim{exec, ms};
Expand All @@ -27,16 +28,17 @@ static cobalt::promise<std::size_t> dummy(asio::any_io_executor exec,
}


static cobalt::promise<std::size_t> nothrow_dummy(asio::any_io_executor exec,
std::chrono::milliseconds ms = std::chrono::milliseconds(50))
static cobalt::promise<std::chrono::milliseconds::rep> nothrow_dummy(
asio::any_io_executor exec,
std::chrono::milliseconds ms = std::chrono::milliseconds(50))
try {
asio::steady_timer tim{exec, ms};
co_await tim.async_wait(cobalt::use_op);
co_return ms.count();
}
catch(...)
{
co_return std::numeric_limits<std::size_t>::max();
co_return std::numeric_limits<std::chrono::milliseconds::rep>::max();
}

static cobalt::generator<int> gen(asio::any_io_executor exec)
Expand Down Expand Up @@ -89,7 +91,7 @@ CO_TEST_CASE("list")
std::mt19937 src{seed};

auto exec = co_await asio::this_coro::executor;
std::vector<cobalt::promise<std::size_t>> vec;
std::vector<cobalt::promise<std::chrono::milliseconds::rep>> vec;
vec.push_back(dummy(exec, std::chrono::milliseconds(100)));
vec.push_back(dummy(exec, std::chrono::milliseconds( 50)));
vec.push_back(dummy(exec, std::chrono::milliseconds(100000)));
Expand Down
2 changes: 1 addition & 1 deletion test/wait_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CO_TEST_CASE("grp")
{
auto e = co_await cobalt::this_coro::executor;

using std::chrono::operator""ms;
using namespace std;

cobalt::wait_group wg;
wg.push_back(gdelay(e));
Expand Down

0 comments on commit 0ff2d4e

Please sign in to comment.