Page MenuHomePhabricator

Please use GitHub pull requests for new patches. Phabricator shutdown timeline

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

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


Group Reviewers
Restricted Project

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

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.Wed, Sep 13, 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.Wed, Sep 13, 2:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptWed, Sep 13, 2:36 PM