From 0d9fedc2d107ebdd824e832709c52b6fe914fe83 Mon Sep 17 00:00:00 2001 From: Chad Austin Date: Mon, 16 Dec 2024 13:45:36 -0800 Subject: [PATCH 1/3] add from_owned_fd to EventFd --- src/sys/eventfd.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs index b7860e683f..f67cebbb0b 100644 --- a/src/sys/eventfd.rs +++ b/src/sys/eventfd.rs @@ -58,6 +58,13 @@ impl EventFd { Self::from_value_and_flags(init_val, EfdFlags::empty()) } + /// Constructs an `EventFd` wrapping an existing `OwnedFd`. + /// + /// Safety: `OwnedFd` is a valid eventfd. + pub unsafe fn from_owned_fd(fd: OwnedFd) -> Self { + Self(fd) + } + /// Enqueues `value` triggers, i.e., adds the integer value supplied in `value` /// to the counter. /// @@ -106,4 +113,4 @@ impl From for OwnedFd { fn from(value: EventFd) -> Self { value.0 } -} \ No newline at end of file +} From 2e4da662fc89c5f44041a0529f2d92485099b104 Mon Sep 17 00:00:00 2001 From: Chad Austin Date: Mon, 16 Dec 2024 13:52:59 -0800 Subject: [PATCH 2/3] update changelog --- changelog/2563.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/2563.added.md diff --git a/changelog/2563.added.md b/changelog/2563.added.md new file mode 100644 index 0000000000..2b61f37bec --- /dev/null +++ b/changelog/2563.added.md @@ -0,0 +1 @@ +Added `from_owned_fd` constructor to `EventFd` From 1a249d6fbf8147a1c10cd8a463a4e25abfaddb85 Mon Sep 17 00:00:00 2001 From: Chad Austin Date: Mon, 16 Dec 2024 14:46:24 -0800 Subject: [PATCH 3/3] fix safety section --- src/sys/eventfd.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs index f67cebbb0b..382a72e75c 100644 --- a/src/sys/eventfd.rs +++ b/src/sys/eventfd.rs @@ -60,7 +60,9 @@ impl EventFd { /// Constructs an `EventFd` wrapping an existing `OwnedFd`. /// - /// Safety: `OwnedFd` is a valid eventfd. + /// # Safety + /// + /// `OwnedFd` is a valid eventfd. pub unsafe fn from_owned_fd(fd: OwnedFd) -> Self { Self(fd) }