This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Split a few utilities out of __threading_support
ClosedPublic

Authored by ldionne on Jan 10 2022, 7:26 AM.

Details

Summary

This change is the basis for a further refactoring where I'm going to
split up the various implementations we have in __threading_support to
make that code easier to understand.

Note that I had to make __convert_to_timespec a template to break
circular dependencies. Concretely, we never seem to use it with anything
other than ::timespec, but I am wary of hardcoding that assumption as
part of this change, since I suspect there's a reason for going through
these hoops in the first place.

Diff Detail

Event Timeline

ldionne created this revision.Jan 10 2022, 7:26 AM
ldionne requested review of this revision.Jan 10 2022, 7:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2022, 7:26 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Quuxplusone requested changes to this revision.Jan 10 2022, 8:37 AM
Quuxplusone added a subscriber: Quuxplusone.

Looks plausible to me, FWIW, but nits.

libcxx/include/__thread/convert_to_timespec.h
27 ↗(On Diff #398634)

In making this a template, you drive-by removed the inline keyword. I thought we weren't doing that. :)
I have a hunch that this helper belongs in __chrono/ not __thread/, but that's not a blocker.

libcxx/include/module.modulemap
906–908

You aren't including any of these detail headers from the actual <thread>. I think you should (or else, if <thread> doesn't actually use them, then they're in the wrong detail directory).

libcxx/src/atomic.cpp
11–12

I'd prefer to just include the public <thread>. I don't know if the Modules build will actually complain about including a private header like this from src/, but I just think it's better hygiene if src/ uses only the public headers.

(Pre-existing: At some point I'd love to find out why some src/*.cpp do e.g. #include "memory" instead of #include <memory>, and whether it'd be safe to change that.)

This revision now requires changes to proceed.Jan 10 2022, 8:37 AM
ldionne updated this revision to Diff 398675.Jan 10 2022, 9:27 AM
ldionne marked 3 inline comments as done.

Address review comments

libcxx/include/__thread/convert_to_timespec.h
27 ↗(On Diff #398634)

In making this a template, you drive-by removed the inline keyword. I thought we weren't doing that. :)

You're right -- I removed it because templates implicitly have the right linkage, but I forgot about the fact that it can mess up optimizations (and I'm still working on figuring out the regression I mentioned elsewhere). I'll put inline back, good catch.

I have a hunch that this helper belongs in __chrono/ not __thread/, but that's not a blocker.

Yeah, I guess you're right, I'll move it there.

libcxx/src/atomic.cpp
11–12

I'd prefer to just include the public <thread>.

Done.

(Pre-existing: At some point I'd love to find out why some src/*.cpp do e.g. #include "memory" instead of #include <memory>, and whether it'd be safe to change that.)

I'm pretty sure it's safe to change that, it's just historical inconsistency.

ldionne updated this revision to Diff 399990.Jan 14 2022, 7:13 AM

Rebase onto <chrono> modularization.

LGTM FWIW.

libcxx/include/__chrono/convert_to_timespec.h
27

In fact __libcpp_timespec_t is unconditionally a typedef for ::timespec; so could we just use ::timespec here?
The template solution isn't too bad, but it still seems like it's working around a problem that shouldn't have been a problem in the first place.

libcxx/include/module.modulemap
370
ldionne accepted this revision as: Restricted Project.Jan 14 2022, 7:29 AM
ldionne added inline comments.
libcxx/include/__chrono/convert_to_timespec.h
27

As I said in the commit message:

Concretely, we never seem to use it with anything other than ::timespec, but I am wary of hardcoding that assumption as part of this change, since I suspect there's a reason for going through these hoops in the first place.

I can refactor that in a subsequent patch so that any fallout is separate from this one.

This revision is now accepted and ready to land.Jan 14 2022, 7:29 AM
ldionne updated this revision to Diff 400100.Jan 14 2022, 12:03 PM

Fix modular CI

ldionne updated this revision to Diff 400836.Jan 18 2022, 7:04 AM

Rebase onto main, CI should be fixed.

This revision was automatically updated to reflect the committed changes.
miyuki added a subscriber: miyuki.Jan 19 2022, 2:30 AM

@ldionne, the reason for using __libcpp_timespec_t is the _LIBCPP_HAS_THREAD_API_EXTERNAL configuration. In that case __libcpp_timespec_t is defined in the __external_threading header.

@ldionne, the reason for using __libcpp_timespec_t is the _LIBCPP_HAS_THREAD_API_EXTERNAL configuration. In that case __libcpp_timespec_t is defined in the __external_threading header.

There you go, I knew there was a reason. Thanks!