-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6d7cbb
commit 431fdf1
Showing
5 changed files
with
62 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use core::sync::atomic::AtomicU32; | ||
|
||
/// Implementation of [`korbis::file::File`] for 11.00. | ||
#[repr(C)] | ||
pub struct File { | ||
pad: [u8; 0x28], | ||
refcnt: AtomicU32, | ||
} | ||
|
||
impl korbis::file::File for File { | ||
fn refcnt(&self) -> &AtomicU32 { | ||
&self.refcnt | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::thread::Thread; | ||
use crate::Kernel; | ||
use core::sync::atomic::{fence, AtomicU32, Ordering}; | ||
|
||
/// Represents `file` structure. | ||
pub trait File: Sized { | ||
/// Returns `f_count` field. | ||
fn refcnt(&self) -> &AtomicU32; | ||
} | ||
|
||
/// RAII struct to decrease `file::f_count` when dropped. | ||
pub struct OwnedFile<K: Kernel> { | ||
kernel: K, | ||
file: *mut K::File, | ||
} | ||
|
||
impl<K: Kernel> Drop for OwnedFile<K> { | ||
fn drop(&mut self) { | ||
// See Drop implementation on Arc how this thing work. | ||
if unsafe { (*self.file).refcnt().fetch_sub(1, Ordering::Release) } != 1 { | ||
return; | ||
} | ||
|
||
fence(Ordering::Acquire); | ||
|
||
// The kernel itself does not check if fdrop is success so we don't need to. | ||
unsafe { self.kernel.fdrop(self.file, K::Thread::current()) }; | ||
} | ||
} |
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