Skip to content

Create a UniqueFd counterpart to SharedFD - #3001

Merged
Databean merged 2 commits into
google:mainfrom
Databean:unique_fd
Aug 12, 2026
Merged

Create a UniqueFd counterpart to SharedFD#3001
Databean merged 2 commits into
google:mainfrom
Databean:unique_fd

Conversation

@Databean

Copy link
Copy Markdown
Member

Sometimes the machinery of std::shared_ptr is not necessary, and the semantics of std::unique_ptr are simpler.

Bug: b/545278508

Duplicates most of the static methods of `SharedFD`, leaving out:

- Functions with complex return types like output SharedFD*s or pairs
- Functions relying on shared_buf.h

Bug: b/545278508
Adds constructor and assignment operators to transparently convert
UniqueFd instances to SharedFD instances, similar to the conversions
supported from std::unique_ptr to std::shared_ptr.

Bug: b/545278508
@Databean
Databean requested a review from jemoreira August 11, 2026 21:49

@jemoreira jemoreira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you plan to do with functions that currently accept a SharedFD by value but don't really care whether it's a SharedFD or UniqueFD?
Have you considered adding a BaseFD class with private constructors/factory methods to be the parent of those two? That would allow code that doesn't care about the fd type to just borrow BaseFD&, and code that cares to use one of the specialized classes to share ownership of the fd with SharedFD or take ownership of it with UniqueFD.

@Databean

Databean commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

In my opinion code that would accept a BaseFD& should instead accept a FileInstance& or one of the pure virtual interfaces in //cuttlefish/io/io.h like Reader& or ReaderWriterSeeker&.

@Databean Databean added kokoro:force-run Trigger a presubmit build unconditionally. kokoro:run Run e2e tests. labels Aug 12, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed kokoro:run Run e2e tests. kokoro:force-run Trigger a presubmit build unconditionally. labels Aug 12, 2026
@Databean
Databean added this pull request to the merge queue Aug 12, 2026
Merged via the queue into google:main with commit c13d385 Aug 12, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants