Skip to content
Snippets Groups Projects
Commit 0bd1cda1 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Cleanup schemes list, remove lazy_static

parent b9e721d4
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,7 @@
#![feature(alloc)]
#![feature(collections)]
#![feature(const_fn)]
#![feature(drop_types_in_const)]
#![feature(question_mark)]
#![no_std]
......@@ -88,8 +89,6 @@ extern crate collections;
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate lazy_static;
extern crate spin;
/// Context management
......
......@@ -11,7 +11,7 @@ use alloc::boxed::Box;
use collections::BTreeMap;
use spin::{Mutex, RwLock};
use spin::{Once, Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
use syscall::Result;
......@@ -20,13 +20,23 @@ use self::debug::DebugScheme;
/// Debug scheme
pub mod debug;
pub type SchemeList = BTreeMap<Box<[u8]>, Arc<Mutex<Box<Scheme + Send>>>>;
/// Schemes list
lazy_static! {
pub static ref SCHEMES: RwLock<BTreeMap<Box<[u8]>, Arc<Mutex<Box<Scheme + Send>>>>> = {
let mut map: BTreeMap<Box<[u8]>, Arc<Mutex<Box<Scheme + Send>>>> = BTreeMap::new();
map.insert(Box::new(*b"debug"), Arc::new(Mutex::new(Box::new(DebugScheme))));
RwLock::new(map)
};
static SCHEMES: Once<RwLock<SchemeList>> = Once::new();
fn init_schemes() -> RwLock<SchemeList> {
let mut map: SchemeList = BTreeMap::new();
map.insert(Box::new(*b"debug"), Arc::new(Mutex::new(Box::new(DebugScheme))));
RwLock::new(map)
}
pub fn schemes() -> RwLockReadGuard<'static, SchemeList> {
SCHEMES.call_once(init_schemes).read()
}
pub fn schemes_mut() -> RwLockWriteGuard<'static, SchemeList> {
SCHEMES.call_once(init_schemes).write()
}
/// A scheme trait, implemented by a scheme handler
......
//! Filesystem syscalls
use scheme;
use super::{Error, Result};
/// Read syscall
......@@ -33,7 +35,7 @@ pub fn open(path: &[u8], flags: usize) -> Result<usize> {
let file = {
if let Some(namespace) = namespace_opt {
let schemes = ::scheme::SCHEMES.read();
let schemes = scheme::schemes();
if let Some(scheme_mutex) = schemes.get(namespace) {
scheme_mutex.lock().open(reference_opt.unwrap_or(b""), flags)
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment