Orbital (#16)
* Port previous ethernet scheme * Add ipd * Fix initfs rebuilds, use QEMU user networking addresses in ipd * Add tcp/udp, netutils, dns, and network config * Add fsync to network driver * Add dns, router, subnet by default * Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks * Add orbital server, WIP * Add futex * Add orbutils and orbital * Update libstd, orbutils, and orbital Move ANSI key encoding to vesad * Add orbital assets * Update orbital * Update to add login manager * Add blocking primitives, block for most things except waitpid, update orbital * Wait in waitpid and IRQ, improvements for other waits * Fevent in root scheme * WIP: Switch to using fevent * Reorganize * Event based e1000d driver * Superuser-only access to some network schemes, display, and disk * Superuser root and irq schemes * Fix orbital
This commit is contained in:
parent
372d44f88c
commit
224c43f761
92 changed files with 3415 additions and 473 deletions
7
kernel/sync/mod.rs
Normal file
7
kernel/sync/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
pub use self::wait_condition::WaitCondition;
|
||||
pub use self::wait_queue::WaitQueue;
|
||||
pub use self::wait_map::WaitMap;
|
||||
|
||||
pub mod wait_condition;
|
||||
pub mod wait_queue;
|
||||
pub mod wait_map;
|
49
kernel/sync/wait_condition.rs
Normal file
49
kernel/sync/wait_condition.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use alloc::arc::Arc;
|
||||
use collections::Vec;
|
||||
use core::mem;
|
||||
use spin::{Mutex, RwLock};
|
||||
|
||||
use context::{self, Context};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WaitCondition {
|
||||
contexts: Mutex<Vec<Arc<RwLock<Context>>>>
|
||||
}
|
||||
|
||||
impl WaitCondition {
|
||||
pub fn new() -> WaitCondition {
|
||||
WaitCondition {
|
||||
contexts: Mutex::new(Vec::new())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn notify(&self) -> usize {
|
||||
let mut contexts = Vec::new();
|
||||
mem::swap(&mut *self.contexts.lock(), &mut contexts);
|
||||
for context_lock in contexts.iter() {
|
||||
context_lock.write().unblock();
|
||||
}
|
||||
contexts.len()
|
||||
}
|
||||
|
||||
pub fn wait(&self) {
|
||||
{
|
||||
let context_lock = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().expect("WaitCondition::wait: no context");
|
||||
context_lock.clone()
|
||||
};
|
||||
|
||||
context_lock.write().block();
|
||||
|
||||
self.contexts.lock().push(context_lock);
|
||||
}
|
||||
unsafe { context::switch(); }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WaitCondition {
|
||||
fn drop(&mut self){
|
||||
self.notify();
|
||||
}
|
||||
}
|
33
kernel/sync/wait_map.rs
Normal file
33
kernel/sync/wait_map.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use collections::BTreeMap;
|
||||
use spin::Mutex;
|
||||
|
||||
use sync::WaitCondition;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WaitMap<K, V> {
|
||||
inner: Mutex<BTreeMap<K, V>>,
|
||||
condition: WaitCondition
|
||||
}
|
||||
|
||||
impl<K, V> WaitMap<K, V> where K: Ord {
|
||||
pub fn new() -> WaitMap<K, V> {
|
||||
WaitMap {
|
||||
inner: Mutex::new(BTreeMap::new()),
|
||||
condition: WaitCondition::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send(&self, key: K, value: V) {
|
||||
self.inner.lock().insert(key, value);
|
||||
self.condition.notify();
|
||||
}
|
||||
|
||||
pub fn receive(&self, key: &K) -> V {
|
||||
loop {
|
||||
if let Some(value) = self.inner.lock().remove(key) {
|
||||
return value;
|
||||
}
|
||||
self.condition.wait();
|
||||
}
|
||||
}
|
||||
}
|
95
kernel/sync/wait_queue.rs
Normal file
95
kernel/sync/wait_queue.rs
Normal file
|
@ -0,0 +1,95 @@
|
|||
use collections::vec_deque::VecDeque;
|
||||
use core::mem;
|
||||
use core::ops::DerefMut;
|
||||
use spin::Mutex;
|
||||
|
||||
use sync::WaitCondition;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WaitQueue<T> {
|
||||
pub inner: Mutex<VecDeque<T>>,
|
||||
pub condition: WaitCondition,
|
||||
}
|
||||
|
||||
impl<T> WaitQueue<T> {
|
||||
pub fn new() -> WaitQueue<T> {
|
||||
WaitQueue {
|
||||
inner: Mutex::new(VecDeque::new()),
|
||||
condition: WaitCondition::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clone(&self) -> WaitQueue<T> where T: Clone {
|
||||
WaitQueue {
|
||||
inner: Mutex::new(self.inner.lock().clone()),
|
||||
condition: WaitCondition::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.inner.lock().is_empty()
|
||||
}
|
||||
|
||||
pub fn receive(&self) -> T {
|
||||
loop {
|
||||
if let Some(value) = self.inner.lock().pop_front() {
|
||||
return value;
|
||||
}
|
||||
self.condition.wait();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn receive_into(&self, buf: &mut [T]) -> usize {
|
||||
let mut i = 0;
|
||||
|
||||
if i < buf.len() {
|
||||
buf[i] = self.receive();
|
||||
i += 1;
|
||||
}
|
||||
|
||||
while i < buf.len() {
|
||||
if let Some(value) = self.inner.lock().pop_front() {
|
||||
buf[i] = value;
|
||||
i += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
i
|
||||
}
|
||||
|
||||
pub fn receive_all(&self) -> VecDeque<T> {
|
||||
loop {
|
||||
{
|
||||
let mut inner = self.inner.lock();
|
||||
if ! inner.is_empty() {
|
||||
let mut swap_inner = VecDeque::new();
|
||||
mem::swap(inner.deref_mut(), &mut swap_inner);
|
||||
return swap_inner;
|
||||
}
|
||||
}
|
||||
self.condition.wait();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send(&self, value: T) -> usize {
|
||||
let len = {
|
||||
let mut inner = self.inner.lock();
|
||||
inner.push_back(value);
|
||||
inner.len()
|
||||
};
|
||||
self.condition.notify();
|
||||
len
|
||||
}
|
||||
|
||||
pub fn send_from(&self, buf: &[T]) -> usize where T: Copy {
|
||||
let len = {
|
||||
let mut inner = self.inner.lock();
|
||||
inner.extend(buf.iter());
|
||||
inner.len()
|
||||
};
|
||||
self.condition.notify();
|
||||
len
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue