This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Support waiting on monotonic clock with ext. threading
AcceptedPublic

Authored by miyuki on Jan 18 2022, 10:35 AM.

Details

Reviewers
ldionne
Quuxplusone
Group Reviewers
Restricted Project
Summary

This patch adds support for using the monotonic clock (steady_clock)
when waiting on a condition variable with a timeout. This feature is
currently implemented for POSIX threads. The patch generalizes it to
be usable with an external threading library by adding
__libcpp_condvar_monotonic_timedwait.

The external threading layer implementors should define
_LIBCPP_CONDVAR_HAS_MONOTONIC_TIMEDWAIT in their __external_threading
header and implement the __libcpp_condvar_monotonic_timedwait function
to use the feature.

Diff Detail

Event Timeline

miyuki requested review of this revision.Jan 18 2022, 10:35 AM
miyuki created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2022, 10:35 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
miyuki updated this revision to Diff 400911.Jan 18 2022, 10:39 AM

Added missing "_LIBCPP_HIDE_FROM_ABI inline"

miyuki updated this revision to Diff 400913.Jan 18 2022, 10:48 AM

No comment from me; this is above my pay grade. :)
But I could bikeshed the name of the macro: The old name reflected the pthreads name, pthread_cond_clockwait -> _LIBCPP_HAS_COND_CLOCKWAIT. The new name reflects nothing we didn't make up ourselves; so maybe it should be more like _LIBCPP_HAS_MONOTONIC_TIMEDWAIT or _LIBCPP_CONDVAR_HAS_MONOTONIC_TIMEDWAIT. My understanding is that "steady" is a WG21-ism for "monotonic": even though you named the new function __libcpp_condvar_steady_timedwait, we never actually use steady_clock anywhere in its signature or implementation. Instead it depends on pthreads' CLOCK_MONOTONIC.

miyuki updated this revision to Diff 401643.Jan 20 2022, 8:00 AM
miyuki retitled this revision from [libcxx] Support waiting on steady clock with ext. threading to [libcxx] Support waiting on monotonic clock with ext. threading.
miyuki edited the summary of this revision. (Show Details)

Renamed steady -> monotonic.

@ldionne, could you please have a look at this patch?

ldionne accepted this revision.Sep 13 2023, 2:36 PM

[Github PR transition cleanup]

@miyuki This seems fine to me in principle. Do you still want to pursue this? If so please rebase it and ping me on Discord.

FWIW the "external threading API" is an area I've discussed several times with other folks that we should overhaul to support better and reduce the complexity for libc++, but this patch is orthogonal.

This revision is now accepted and ready to land.Sep 13 2023, 2:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2023, 2:36 PM