This is an archive of the discontinued LLVM Phabricator instance.

[libc] move fork into threads folder
ClosedPublic

Authored by michaelrj on Nov 11 2022, 2:02 PM.

Details

Summary

Fork, as a thread function, should go in the threads folder.
Additionally, it depends on the thread mutex, and it was causing build
issues for targets where we don't support threads.

Diff Detail

Event Timeline

michaelrj created this revision.Nov 11 2022, 2:02 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 11 2022, 2:02 PM
michaelrj requested review of this revision.Nov 11 2022, 2:02 PM
lntue accepted this revision.Nov 11 2022, 3:44 PM
lntue added a reviewer: lntue.
This revision is now accepted and ready to land.Nov 11 2022, 3:44 PM
This revision was automatically updated to reflect the committed changes.

I did not go into the specifics of this patch (I am on vacation) but I have concern about it because of the subject:

Fork, as a thread function, should go in the threads folder.
Additionally, it depends on the thread mutex, and it was causing build
issues for targets where we don't support threads.

Two things:

  1. Why is fork a thread function?
  2. If the logic of "it depends on the thread mutex" is applied to other parts of the libc (for example File), they all should be moved into the threads directory.

I meant that the fork_callbacks utility should be moved into the threads folder since it depends on the other utilities in the threads folder and is only used by the pthreads utilities. I think having file be separate makes sense because that's a category that is more specific than threads. The goal is to group similar things so that they can be found, and while I would expect fork related utilities to be in a threads folder, I wouldn't expect file related utilities to be in a threads folder.

I meant that the fork_callbacks utility should be moved into the threads folder since it depends on the other utilities in the threads folder and is only used by the pthreads utilities. I think having file be separate makes sense because that's a category that is more specific than threads. The goal is to group similar things so that they can be found, and while I would expect fork related utilities to be in a threads folder, I wouldn't expect file related utilities to be in a threads folder.

I still don't understand - perhaps you are thinking fork is related to threads? Also, can you explain what prompted this change? Was something failing on arm32?

lntue added a comment.Nov 14 2022, 3:24 PM

I meant that the fork_callbacks utility should be moved into the threads folder since it depends on the other utilities in the threads folder and is only used by the pthreads utilities. I think having file be separate makes sense because that's a category that is more specific than threads. The goal is to group similar things so that they can be found, and while I would expect fork related utilities to be in a threads folder, I wouldn't expect file related utilities to be in a threads folder.

I still don't understand - perhaps you are thinking fork is related to threads? Also, can you explain what prompted this change? Was something failing on arm32?

It was actually blocking macos builds.

yes, the windows build was failing (and anything else that doesn't have a threads implementation) because the fork_callbacks cmake target was including mutex unconditionally.

yes, the windows build was failing (and anything else that doesn't have a threads implementation) because the fork_callbacks cmake target was including mutex unconditionally.

The fork callback machinery uses a mutex and is not related to threads. So, the pattern to follow would be this: https://github.com/llvm/llvm-project/blob/main/libc/src/__support/File/CMakeLists.txt#L1. Which is to exclude listing a target if mutex is not available. This patch is essentially doing that, but clubbing fork callbacks machinery with thread machinery is incorrect.

lntue added a comment.Nov 14 2022, 3:59 PM

yes, the windows build was failing (and anything else that doesn't have a threads implementation) because the fork_callbacks cmake target was including mutex unconditionally.

The fork callback machinery uses a mutex and is not related to threads. So, the pattern to follow would be this: https://github.com/llvm/llvm-project/blob/main/libc/src/__support/File/CMakeLists.txt#L1. Which is to exclude listing a target if mutex is not available. This patch is essentially doing that, but clubbing fork callbacks machinery with thread machinery is incorrect.

Putting fork_callback inside the target check (without the return part) and adding message Skipping ... with reason similar to unit tests sounds good to me.