-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve object releasers and cleanup usage sites
- Loading branch information
1 parent
a4e6255
commit 13c32c9
Showing
4 changed files
with
82 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
// Take a look at the license at the top of the repository in the LICENSE file. | ||
|
||
pub(crate) struct IOReleaser(super::ffi::io_object_t); | ||
use std::num::NonZeroU32; | ||
|
||
type IoObject = NonZeroU32; | ||
|
||
pub(crate) struct IOReleaser(IoObject); | ||
|
||
impl IOReleaser { | ||
pub(crate) fn new(obj: u32) -> Option<Self> { | ||
if obj == 0 { | ||
None | ||
} else { | ||
Some(Self(obj)) | ||
} | ||
IoObject::new(obj).map(Self) | ||
} | ||
|
||
pub(crate) unsafe fn new_unchecked(obj: u32) -> Self { | ||
// Chance at catching in-development mistakes | ||
debug_assert_ne!(obj, 0); | ||
Self(IoObject::new_unchecked(obj)) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn inner(&self) -> u32 { | ||
self.0 | ||
self.0.get() | ||
} | ||
} | ||
|
||
impl Drop for IOReleaser { | ||
fn drop(&mut self) { | ||
if self.0 != 0 { | ||
unsafe { super::ffi::IOObjectRelease(self.0 as _) }; | ||
} | ||
unsafe { super::ffi::IOObjectRelease(self.0.get() as _) }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters