2016-09-24 01:54:39 +02:00
|
|
|
use alloc::arc::{Arc, Weak};
|
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
2016-10-14 01:21:42 +02:00
|
|
|
use collections::BTreeMap;
|
|
|
|
use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
2016-09-24 01:54:39 +02:00
|
|
|
|
|
|
|
use context;
|
2016-11-13 21:47:04 +01:00
|
|
|
use scheme::{FileHandle, SchemeId};
|
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
2016-10-14 01:21:42 +02:00
|
|
|
use sync::WaitQueue;
|
2016-09-24 01:54:39 +02:00
|
|
|
use syscall::data::Event;
|
|
|
|
|
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
2016-10-14 01:21:42 +02:00
|
|
|
type EventList = Weak<WaitQueue<Event>>;
|
2016-09-24 01:54:39 +02:00
|
|
|
|
2016-11-03 16:06:44 +01:00
|
|
|
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
|
|
|
pub struct RegKey {
|
2016-11-04 13:49:44 +01:00
|
|
|
scheme_id: SchemeId,
|
2016-11-03 16:06:44 +01:00
|
|
|
event_id: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
|
|
|
pub struct ProcessKey {
|
2016-11-13 15:36:52 +01:00
|
|
|
context_id: context::context::ContextId,
|
2016-11-13 21:47:04 +01:00
|
|
|
fd: FileHandle,
|
2016-11-03 16:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type Registry = BTreeMap<RegKey, BTreeMap<ProcessKey, EventList>>;
|
2016-09-24 01:54:39 +02:00
|
|
|
|
|
|
|
static REGISTRY: Once<RwLock<Registry>> = Once::new();
|
|
|
|
|
|
|
|
/// Initialize registry, called if needed
|
|
|
|
fn init_registry() -> RwLock<Registry> {
|
|
|
|
RwLock::new(Registry::new())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the global schemes list, const
|
|
|
|
fn registry() -> RwLockReadGuard<'static, Registry> {
|
|
|
|
REGISTRY.call_once(init_registry).read()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the global schemes list, mutable
|
|
|
|
pub fn registry_mut() -> RwLockWriteGuard<'static, Registry> {
|
|
|
|
REGISTRY.call_once(init_registry).write()
|
|
|
|
}
|
|
|
|
|
2016-11-13 21:47:04 +01:00
|
|
|
pub fn register(fd: FileHandle, scheme_id: SchemeId, event_id: usize) -> bool {
|
2016-09-24 01:54:39 +02:00
|
|
|
let (context_id, events) = {
|
|
|
|
let contexts = context::contexts();
|
|
|
|
let context_lock = contexts.current().expect("event::register: No context");
|
|
|
|
let context = context_lock.read();
|
|
|
|
(context.id, Arc::downgrade(&context.events))
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut registry = registry_mut();
|
2016-11-03 16:06:44 +01:00
|
|
|
let entry = registry.entry(RegKey {
|
|
|
|
scheme_id: scheme_id,
|
|
|
|
event_id: event_id
|
|
|
|
}).or_insert_with(|| {
|
2016-09-24 01:54:39 +02:00
|
|
|
BTreeMap::new()
|
|
|
|
});
|
2016-11-03 16:06:44 +01:00
|
|
|
let process_key = ProcessKey {
|
|
|
|
context_id: context_id,
|
|
|
|
fd: fd
|
|
|
|
};
|
|
|
|
if entry.contains_key(&process_key) {
|
2016-09-24 01:54:39 +02:00
|
|
|
false
|
|
|
|
} else {
|
2016-11-03 16:06:44 +01:00
|
|
|
entry.insert(process_key, events);
|
2016-09-24 01:54:39 +02:00
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-13 21:47:04 +01:00
|
|
|
pub fn unregister(fd: FileHandle, scheme_id: SchemeId, event_id: usize) {
|
2016-09-24 01:54:39 +02:00
|
|
|
let mut registry = registry_mut();
|
|
|
|
|
|
|
|
let mut remove = false;
|
2016-11-03 16:06:44 +01:00
|
|
|
let key = RegKey {
|
|
|
|
scheme_id: scheme_id,
|
|
|
|
event_id: event_id
|
|
|
|
};
|
|
|
|
if let Some(entry) = registry.get_mut(&key) {
|
|
|
|
let process_key = ProcessKey {
|
|
|
|
context_id: context::context_id(),
|
|
|
|
fd: fd,
|
|
|
|
};
|
|
|
|
entry.remove(&process_key);
|
2016-09-24 01:54:39 +02:00
|
|
|
|
|
|
|
if entry.is_empty() {
|
|
|
|
remove = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if remove {
|
2016-11-03 16:06:44 +01:00
|
|
|
registry.remove(&key);
|
2016-09-24 01:54:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 13:49:44 +01:00
|
|
|
pub fn trigger(scheme_id: SchemeId, event_id: usize, flags: usize, data: usize) {
|
2016-09-24 01:54:39 +02:00
|
|
|
let registry = registry();
|
2016-11-03 16:06:44 +01:00
|
|
|
let key = RegKey {
|
|
|
|
scheme_id: scheme_id,
|
|
|
|
event_id: event_id
|
|
|
|
};
|
|
|
|
if let Some(event_lists) = registry.get(&key) {
|
2016-09-24 01:54:39 +02:00
|
|
|
for entry in event_lists.iter() {
|
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
2016-10-14 01:21:42 +02:00
|
|
|
if let Some(event_list) = entry.1.upgrade() {
|
|
|
|
event_list.send(Event {
|
2016-11-13 21:47:04 +01:00
|
|
|
id: (entry.0).fd.into(),
|
2016-09-24 01:54:39 +02:00
|
|
|
flags: flags,
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|