Converting scheme ids into a new type SchemeId

Keeping scheme ids (and pids, and file handles, ...) as usize is a
footgun. Let's remove it.
This commit is contained in:
David Teller 2016-11-04 13:49:44 +01:00
parent 9f7c20bacf
commit d16515ea12
10 changed files with 40 additions and 28 deletions

View file

@ -3,6 +3,7 @@ use collections::BTreeMap;
use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
use context;
use scheme::SchemeId;
use sync::WaitQueue;
use syscall::data::Event;
@ -10,7 +11,7 @@ type EventList = Weak<WaitQueue<Event>>;
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub struct RegKey {
scheme_id: usize,
scheme_id: SchemeId,
event_id: usize,
}
@ -39,7 +40,7 @@ pub fn registry_mut() -> RwLockWriteGuard<'static, Registry> {
REGISTRY.call_once(init_registry).write()
}
pub fn register(fd: usize, scheme_id: usize, event_id: usize) -> bool {
pub fn register(fd: usize, 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");
@ -66,7 +67,7 @@ pub fn register(fd: usize, scheme_id: usize, event_id: usize) -> bool {
}
}
pub fn unregister(fd: usize, scheme_id: usize, event_id: usize) {
pub fn unregister(fd: usize, scheme_id: SchemeId, event_id: usize) {
let mut registry = registry_mut();
let mut remove = false;
@ -91,7 +92,7 @@ pub fn unregister(fd: usize, scheme_id: usize, event_id: usize) {
}
}
pub fn trigger(scheme_id: usize, event_id: usize, flags: usize, data: usize) {
pub fn trigger(scheme_id: SchemeId, event_id: usize, flags: usize, data: usize) {
let registry = registry();
let key = RegKey {
scheme_id: scheme_id,

View file

@ -1,11 +1,13 @@
//! File struct
use scheme::SchemeId;
/// A file
//TODO: Close on exec
#[derive(Copy, Clone, Debug)]
pub struct File {
/// The scheme that this file refers to
pub scheme: usize,
pub scheme: SchemeId,
/// The number the scheme uses to refer to this file
pub number: usize,
/// If events are on, this is the event ID