Skip to content

[CLR][NFCI] Refactor the unique file descriptor management#4264

Draft
steffenlarsen wants to merge 1 commit intodevelopfrom
users/steffenlarsen/fd_management
Draft

[CLR][NFCI] Refactor the unique file descriptor management#4264
steffenlarsen wants to merge 1 commit intodevelopfrom
users/steffenlarsen/fd_management

Conversation

@steffenlarsen
Copy link

Motivation

The tracking and management of unique file descriptors for fatbin files currently uses std::shared_ptr but relies on use_count() which is considered imprecise as new uses can be created between reads. To amend this, the implementation can directly utilize the smart pointers to have them clean up descriptors themselves.

Technical Details

This patch changes the management of unique file descriptors for fat binary files. The main change is that the PlatformState class now now contains a map of weak pointers to the unique file descriptor and the individual file descriptors manage their own lifetime by calling back into the PlatformState when they are destroyed. This allows the implementation to not rely on the user count of the shared pointers, which are only considered accurate when they are 0 (as there could be new shared pointers being created at the same time as others are being destroyed).

In addition to this, the image management inside the FatBinary class has been moved to the new ManagedUniqueFD struct, which is now in charge of unmapping the image if it was mapped.

JIRA ID

N/A

Test Plan

No functional changes are intended with this, so current testing should be sufficient.

Test Result

No functional changes are intended with this, so current testing should be sufficient.

Submission Checklist

This commit changes the management of unique file descriptors for fat
binary files. The main change is that the `PlatformState` class now
now contains a map of weak pointers to the unique file descriptor and
the individual file descriptors manage their own lifetime by calling
back into the `PlatformState` when they are destroyed. This allows the
implementation to not rely on the user count of the shared pointers,
which are only considered accurate when they are 0 (as there could be
new shared pointers being created at the same time as others are being
destroyed).

In addition to this, the image management inside the `FatBinary` class
has been moved to the new `ManagedUniqueFD` struct, which is now in
charge of unmapping the image if it was mapped.

Signed-off-by: Steffen Holst Larsen <sholstla@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant