Skip to content

Commit

Permalink
Add from_owned_fd constructor to EventFd (#2563)
Browse files Browse the repository at this point in the history
* add from_owned_fd to EventFd

* update changelog

* fix safety section
  • Loading branch information
chadaustin authored Dec 17, 2024
1 parent b003c2f commit 5674377
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/2563.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `from_owned_fd` constructor to `EventFd`
11 changes: 10 additions & 1 deletion src/sys/eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ 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.
///
Expand Down Expand Up @@ -106,4 +115,4 @@ impl From<EventFd> for OwnedFd {
fn from(value: EventFd) -> Self {
value.0
}
}
}

0 comments on commit 5674377

Please sign in to comment.