From: Jonathan Wakely <jwakely@redhat.com>
To: Thomas Rodgers <rodgert@appliantology.com>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org,
trodgers@redhat.com, Thomas Rodgers <rodgert@twrodgers.com>
Subject: Re: [PATCH] [libstdc++] Refactor/cleanup of atomic wait implementation
Date: Tue, 20 Apr 2021 14:38:02 +0100 [thread overview]
Message-ID: <20210420133802.GL3008@redhat.com> (raw)
In-Reply-To: <20210419192305.406972-1-rodgert@appliantology.com>
On 19/04/21 12:23 -0700, Thomas Rodgers wrote:
>+ struct __timed_backoff_spin_policy
>+ {
>+ __wait_clock_t::time_point _M_deadline;
>+ __wait_clock_t::time_point _M_t0;
>+
>+ template<typename _Clock, typename _Dur>
>+ __timed_backoff_spin_policy(chrono::time_point<_Clock, _Dur>
>+ __deadline = _Clock::time_point::max(),
>+ chrono::time_point<_Clock, _Dur>
>+ __t0 = _Clock::now()) noexcept
>+ : _M_deadline(__to_wait_clock(__deadline))
>+ , _M_t0(__to_wait_clock(__t0))
>+ { }
>+
>+ bool
>+ operator()() const noexcept
> {
>- static_assert(sizeof(__timed_waiters) == sizeof(__waiters));
>- return static_cast<__timed_waiters&>(__waiters::_S_for(__t));
>+ using namespace literals::chrono_literals;
>+ auto __now = __wait_clock_t::now();
>+ if (_M_deadline <= __now)
>+ return false;
>+
>+ auto __elapsed = __now - _M_t0;
>+ if (__elapsed > 128ms)
>+ {
>+ this_thread::sleep_for(64ms);
>+ }
>+ else if (__elapsed > 64us)
>+ {
>+ this_thread::sleep_for(__elapsed / 2);
>+ }
>+ else if (__elapsed > 4us)
>+ {
>+ __thread_yield();
>+ }
>+ else
>+ return false;
Ah, the reason for some of the time outs I'm seeing is that this
function doesn't return anything!
/home/jwakely/gcc/12/include/c++/12.0.0/bits/atomic_timed_wait.h: In member function 'bool std::__detail::__timed_backoff_spin_policy::operator()() const':
/home/jwakely/gcc/12/include/c++/12.0.0/bits/atomic_timed_wait.h:259:7: warning: control reaches end of non-void function [-Wreturn-type]
259 | }
| ^
Should it return true if it waited?
next prev parent reply other threads:[~2021-04-20 13:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-22 21:53 Thomas Rodgers
2021-02-23 21:57 ` Thomas Rodgers
2021-03-03 15:14 ` Jonathan Wakely
2021-03-03 17:31 ` Jonathan Wakely
2021-03-23 19:00 ` Thomas Rodgers
2021-04-15 12:46 ` Jonathan Wakely
2021-04-19 19:23 ` Thomas Rodgers
2021-04-20 9:18 ` Jonathan Wakely
2021-04-20 11:04 ` Jonathan Wakely
2021-04-20 11:41 ` Jonathan Wakely
2021-04-20 14:25 ` Jonathan Wakely
2021-04-20 14:26 ` Jonathan Wakely
2021-04-20 12:02 ` Jonathan Wakely
2021-04-20 13:20 ` Jonathan Wakely
2021-04-20 13:28 ` Jonathan Wakely
2021-04-20 13:38 ` Jonathan Wakely [this message]
2021-04-20 13:50 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210420133802.GL3008@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=rodgert@appliantology.com \
--cc=rodgert@twrodgers.com \
--cc=trodgers@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).