Skip to content

Commit

Permalink
Count poll and run branchlessly
Browse files Browse the repository at this point in the history
Note: The same condition can be expressed by

n += (~n > 0); 
or
n += (~n != 0);
  • Loading branch information
Andersama authored Sep 13, 2024
1 parent efdc25a commit c61cf02
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions asio/include/asio/detail/impl/win_iocp_io_context.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ size_t win_iocp_io_context::run(asio::error_code& ec)
thread_call_stack::context ctx(this, this_thread);

size_t n = 0;
size_t loop_count_limit = (std::numeric_limits<size_t>::max)();
while (do_one(INFINITE, this_thread, ec))
if (n != (std::numeric_limits<size_t>::max)())
++n;
n += (n != loop_count_limit);
return n;
}

Expand Down Expand Up @@ -251,9 +251,9 @@ size_t win_iocp_io_context::poll(asio::error_code& ec)
thread_call_stack::context ctx(this, this_thread);

size_t n = 0;
while (do_one(0, this_thread, ec))
if (n != (std::numeric_limits<size_t>::max)())
++n;
size_t loop_count_limit = (std::numeric_limits<size_t>::max)();
while (do_one(INFINITE, this_thread, ec))
n += (n != loop_count_limit);
return n;
}

Expand Down

0 comments on commit c61cf02

Please sign in to comment.