Converting file handles into a new type FileHandle
Keeping file handles (and pids, and scheme id, ...) as usize is a footgun. Let's remove it.
This commit is contained in:
parent
37a34ab7f7
commit
9c90a8fe42
7 changed files with 53 additions and 43 deletions
|
|
@ -3,7 +3,7 @@ use collections::BTreeMap;
|
|||
use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
|
||||
use context;
|
||||
use scheme::SchemeId;
|
||||
use scheme::{FileHandle, SchemeId};
|
||||
use sync::WaitQueue;
|
||||
use syscall::data::Event;
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ pub struct RegKey {
|
|||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct ProcessKey {
|
||||
context_id: context::context::ContextId,
|
||||
fd: usize,
|
||||
fd: FileHandle,
|
||||
}
|
||||
|
||||
type Registry = BTreeMap<RegKey, BTreeMap<ProcessKey, EventList>>;
|
||||
|
|
@ -40,7 +40,7 @@ pub fn registry_mut() -> RwLockWriteGuard<'static, Registry> {
|
|||
REGISTRY.call_once(init_registry).write()
|
||||
}
|
||||
|
||||
pub fn register(fd: usize, scheme_id: SchemeId, event_id: usize) -> bool {
|
||||
pub fn register(fd: FileHandle, scheme_id: SchemeId, event_id: usize) -> bool {
|
||||
let (context_id, events) = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().expect("event::register: No context");
|
||||
|
|
@ -67,7 +67,7 @@ pub fn register(fd: usize, scheme_id: SchemeId, event_id: usize) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn unregister(fd: usize, scheme_id: SchemeId, event_id: usize) {
|
||||
pub fn unregister(fd: FileHandle, scheme_id: SchemeId, event_id: usize) {
|
||||
let mut registry = registry_mut();
|
||||
|
||||
let mut remove = false;
|
||||
|
|
@ -102,7 +102,7 @@ pub fn trigger(scheme_id: SchemeId, event_id: usize, flags: usize, data: usize)
|
|||
for entry in event_lists.iter() {
|
||||
if let Some(event_list) = entry.1.upgrade() {
|
||||
event_list.send(Event {
|
||||
id: (entry.0).fd,
|
||||
id: (entry.0).fd.into(),
|
||||
flags: flags,
|
||||
data: data
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue