Remove a lot of dead code
This commit is contained in:
@@ -35,8 +35,5 @@ pub const KERNEL_PERCPU_SIZE: usize = 1_usize << KERNEL_PERCPU_SHIFT;
|
||||
pub const PHYS_OFFSET: usize = 0xFFFF_8000_0000_0000;
|
||||
pub const PHYS_PML4: usize = (PHYS_OFFSET & PML4_MASK)/PML4_SIZE;
|
||||
|
||||
/// Offset to user image
|
||||
pub const USER_OFFSET: usize = 0;
|
||||
|
||||
/// End offset of the user image, i.e. kernel start
|
||||
pub const USER_END_OFFSET: usize = 256 * PML4_SIZE;
|
||||
|
||||
@@ -28,8 +28,5 @@
|
||||
// This needs to match RMM's PHYS_OFFSET
|
||||
pub const PHYS_OFFSET: usize = 0x8000_0000;
|
||||
|
||||
/// Offset to user image
|
||||
pub const USER_OFFSET: usize = 0;
|
||||
|
||||
/// End offset of the user image, i.e. kernel start
|
||||
pub const USER_END_OFFSET: usize = 0x8000_0000;
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
//! # Page table entry
|
||||
//! Some code borrowed from [Phil Opp's Blog](http://os.phil-opp.com/modifying-page-tables.html)
|
||||
|
||||
use crate::memory::Frame;
|
||||
|
||||
use super::{PageFlags, PhysicalAddress, RmmA, RmmArch};
|
||||
|
||||
/// A page table entry
|
||||
#[repr(packed(8))]
|
||||
pub struct Entry(u64);
|
||||
|
||||
bitflags! {
|
||||
pub struct EntryFlags: usize {
|
||||
const NO_CACHE = 1 << 4;
|
||||
const HUGE_PAGE = 1 << 7;
|
||||
const GLOBAL = 1 << 8;
|
||||
}
|
||||
}
|
||||
|
||||
pub const COUNTER_MASK: u64 = 0x3ff0_0000_0000_0000;
|
||||
|
||||
impl Entry {
|
||||
/// Clear entry
|
||||
pub fn set_zero(&mut self) {
|
||||
self.0 = 0;
|
||||
}
|
||||
|
||||
/// Is the entry unused?
|
||||
pub fn is_unused(&self) -> bool {
|
||||
self.0 == (self.0 & COUNTER_MASK)
|
||||
}
|
||||
|
||||
/// Make the entry unused
|
||||
pub fn set_unused(&mut self) {
|
||||
self.0 &= COUNTER_MASK;
|
||||
}
|
||||
|
||||
/// Get the address this page references
|
||||
pub fn address(&self) -> PhysicalAddress {
|
||||
PhysicalAddress::new(self.0 as usize & RmmA::PAGE_ADDRESS_MASK)
|
||||
}
|
||||
|
||||
/// Get the current entry flags
|
||||
pub fn flags(&self) -> PageFlags<RmmA> {
|
||||
unsafe { PageFlags::from_data((self.0 as usize & RmmA::ENTRY_FLAGS_MASK) & !(COUNTER_MASK as usize)) }
|
||||
}
|
||||
|
||||
/// Get the associated frame, if available
|
||||
pub fn pointed_frame(&self) -> Option<Frame> {
|
||||
if self.flags().has_present() {
|
||||
Some(Frame::containing_address(self.address()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set(&mut self, frame: Frame, flags: PageFlags<RmmA>) {
|
||||
debug_assert!(frame.start_address().data() & !RmmA::PAGE_ADDRESS_MASK == 0);
|
||||
self.0 = (frame.start_address().data() as u64) | (flags.data() as u64) | (self.0 & COUNTER_MASK);
|
||||
}
|
||||
|
||||
/// Get bits 52-61 in entry, used as counter for page table
|
||||
pub fn counter_bits(&self) -> u64 {
|
||||
(self.0 & COUNTER_MASK) >> 52
|
||||
}
|
||||
|
||||
/// Set bits 52-61 in entry, used as counter for page table
|
||||
pub fn set_counter_bits(&mut self, count: u64) {
|
||||
self.0 = (self.0 & !COUNTER_MASK) | (count << 52);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn entry_has_required_arch_alignment() {
|
||||
use super::Entry;
|
||||
assert!(core::mem::align_of::<Entry>() >= core::mem::align_of::<u64>(), "alignment of Entry is less than the required alignment of u64 ({} < {})", core::mem::align_of::<Entry>(), core::mem::align_of::<u64>());
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,16 @@ pub use super::CurrentRmmArch as RmmA;
|
||||
pub type PageMapper = rmm::PageMapper<RmmA, crate::arch::rmm::LockedAllocator>;
|
||||
pub use crate::rmm::KernelMapper;
|
||||
|
||||
pub mod entry;
|
||||
pub mod entry {
|
||||
bitflags! {
|
||||
pub struct EntryFlags: usize {
|
||||
const NO_CACHE = 1 << 4;
|
||||
const HUGE_PAGE = 1 << 7;
|
||||
const GLOBAL = 1 << 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod mapper;
|
||||
|
||||
/// Number of entries per page table
|
||||
|
||||
@@ -28,8 +28,5 @@ pub const KERNEL_HEAP_SIZE: usize = 1 * 1024 * 1024; // 1 MB
|
||||
pub const PHYS_OFFSET: usize = 0xFFFF_8000_0000_0000;
|
||||
pub const PHYS_PML4: usize = (PHYS_OFFSET & PML4_MASK)/PML4_SIZE;
|
||||
|
||||
/// Offset to user image
|
||||
pub const USER_OFFSET: usize = 0;
|
||||
|
||||
/// End offset of the user image, i.e. kernel start
|
||||
pub const USER_END_OFFSET: usize = 256 * PML4_SIZE;
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
//! # Page table entry
|
||||
//! Some code borrowed from [Phil Opp's Blog](http://os.phil-opp.com/modifying-page-tables.html)
|
||||
|
||||
use crate::memory::Frame;
|
||||
|
||||
use super::{PageFlags, PhysicalAddress, RmmA, RmmArch};
|
||||
|
||||
/// A page table entry
|
||||
#[repr(packed(8))]
|
||||
pub struct Entry(u64);
|
||||
|
||||
bitflags! {
|
||||
pub struct EntryFlags: usize {
|
||||
const NO_CACHE = 1 << 4;
|
||||
const HUGE_PAGE = 1 << 7;
|
||||
const GLOBAL = 1 << 8;
|
||||
}
|
||||
}
|
||||
|
||||
pub const COUNTER_MASK: u64 = 0x3ff0_0000_0000_0000;
|
||||
|
||||
impl Entry {
|
||||
/// Clear entry
|
||||
pub fn set_zero(&mut self) {
|
||||
self.0 = 0;
|
||||
}
|
||||
|
||||
/// Is the entry unused?
|
||||
pub fn is_unused(&self) -> bool {
|
||||
self.0 == (self.0 & COUNTER_MASK)
|
||||
}
|
||||
|
||||
/// Make the entry unused
|
||||
pub fn set_unused(&mut self) {
|
||||
self.0 &= COUNTER_MASK;
|
||||
}
|
||||
|
||||
/// Get the address this page references
|
||||
pub fn address(&self) -> PhysicalAddress {
|
||||
PhysicalAddress::new(self.0 as usize & RmmA::PAGE_ADDRESS_MASK)
|
||||
}
|
||||
|
||||
/// Get the current entry flags
|
||||
pub fn flags(&self) -> PageFlags<RmmA> {
|
||||
unsafe { PageFlags::from_data((self.0 as usize & RmmA::ENTRY_FLAGS_MASK) & !(COUNTER_MASK as usize)) }
|
||||
}
|
||||
|
||||
/// Get the associated frame, if available
|
||||
pub fn pointed_frame(&self) -> Option<Frame> {
|
||||
if self.flags().has_present() {
|
||||
Some(Frame::containing_address(self.address()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set(&mut self, frame: Frame, flags: PageFlags<RmmA>) {
|
||||
debug_assert!(frame.start_address().data() & !RmmA::PAGE_ADDRESS_MASK == 0);
|
||||
self.0 = (frame.start_address().data() as u64) | (flags.data() as u64) | (self.0 & COUNTER_MASK);
|
||||
}
|
||||
|
||||
/// Get bits 52-61 in entry, used as counter for page table
|
||||
pub fn counter_bits(&self) -> u64 {
|
||||
(self.0 & COUNTER_MASK) >> 52
|
||||
}
|
||||
|
||||
/// Set bits 52-61 in entry, used as counter for page table
|
||||
pub fn set_counter_bits(&mut self, count: u64) {
|
||||
self.0 = (self.0 & !COUNTER_MASK) | (count << 52);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn entry_has_required_arch_alignment() {
|
||||
use super::Entry;
|
||||
assert!(core::mem::align_of::<Entry>() >= core::mem::align_of::<u64>(), "alignment of Entry is less than the required alignment of u64 ({} < {})", core::mem::align_of::<Entry>(), core::mem::align_of::<u64>());
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,17 @@ pub use super::CurrentRmmArch as RmmA;
|
||||
pub type PageMapper = rmm::PageMapper<RmmA, crate::arch::rmm::LockedAllocator>;
|
||||
pub use crate::rmm::KernelMapper;
|
||||
|
||||
pub mod entry;
|
||||
pub mod mapper;
|
||||
pub mod entry {
|
||||
bitflags! {
|
||||
pub struct EntryFlags: usize {
|
||||
const NO_CACHE = 1 << 4;
|
||||
const HUGE_PAGE = 1 << 7;
|
||||
const GLOBAL = 1 << 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Number of entries per page table
|
||||
pub const ENTRY_COUNT: usize = RmmA::PAGE_ENTRIES;
|
||||
pub mod mapper;
|
||||
|
||||
/// Size of pages
|
||||
pub const PAGE_SIZE: usize = RmmA::PAGE_SIZE;
|
||||
|
||||
+3
-74
@@ -15,7 +15,7 @@ use crate::arch::{interrupt::InterruptStack, paging::PAGE_SIZE};
|
||||
use crate::common::aligned_box::AlignedBox;
|
||||
use crate::common::unique::Unique;
|
||||
use crate::context::{self, arch};
|
||||
use crate::context::file::{FileDescriptor, FileDescription};
|
||||
use crate::context::file::FileDescriptor;
|
||||
use crate::context::memory::AddrSpace;
|
||||
use crate::ipi::{ipi, IpiKind, IpiTarget};
|
||||
use crate::paging::{RmmA, RmmArch};
|
||||
@@ -24,7 +24,7 @@ use crate::scheme::{SchemeNamespace, FileHandle, CallerCtx};
|
||||
use crate::sync::WaitMap;
|
||||
|
||||
use crate::syscall::data::SigAction;
|
||||
use crate::syscall::error::{Result, Error, EAGAIN, EINVAL, ESRCH};
|
||||
use crate::syscall::error::{Result, Error, EAGAIN, ESRCH};
|
||||
use crate::syscall::flag::{SIG_DFL, SigActionFlags};
|
||||
|
||||
/// Unique identifier for a context (i.e. `pid`).
|
||||
@@ -129,77 +129,6 @@ impl PartialEq for WaitpidKey {
|
||||
|
||||
impl Eq for WaitpidKey {}
|
||||
|
||||
pub struct ContextSnapshot {
|
||||
// Copy fields
|
||||
pub id: ContextId,
|
||||
pub pgid: ContextId,
|
||||
pub ppid: ContextId,
|
||||
pub ruid: u32,
|
||||
pub rgid: u32,
|
||||
pub rns: SchemeNamespace,
|
||||
pub euid: u32,
|
||||
pub egid: u32,
|
||||
pub ens: SchemeNamespace,
|
||||
pub sigmask: [u64; 2],
|
||||
pub umask: usize,
|
||||
pub status: Status,
|
||||
pub status_reason: &'static str,
|
||||
pub running: bool,
|
||||
pub cpu_id: Option<LogicalCpuId>,
|
||||
pub cpu_time: u128,
|
||||
pub sched_affinity: LogicalCpuSet,
|
||||
pub syscall: Option<(usize, usize, usize, usize, usize, usize)>,
|
||||
// Clone fields
|
||||
//TODO: is there a faster way than allocation?
|
||||
pub name: Box<str>,
|
||||
pub files: Vec<Option<FileDescription>>,
|
||||
}
|
||||
|
||||
impl ContextSnapshot {
|
||||
//TODO: Should this accept &mut Context to ensure name/files will not change?
|
||||
pub fn new(context: &Context) -> Self {
|
||||
let name = context.name.clone().into_owned().into_boxed_str();
|
||||
let mut files = Vec::new();
|
||||
for descriptor_opt in context.files.read().iter() {
|
||||
let description = if let Some(descriptor) = descriptor_opt {
|
||||
let description = descriptor.description.read();
|
||||
Some(FileDescription {
|
||||
namespace: description.namespace,
|
||||
scheme: description.scheme,
|
||||
number: description.number,
|
||||
flags: description.flags,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
files.push(description);
|
||||
}
|
||||
|
||||
Self {
|
||||
id: context.id,
|
||||
pgid: context.pgid,
|
||||
ppid: context.ppid,
|
||||
ruid: context.ruid,
|
||||
rgid: context.rgid,
|
||||
rns: context.rns,
|
||||
euid: context.euid,
|
||||
egid: context.egid,
|
||||
ens: context.ens,
|
||||
sigmask: context.sigmask,
|
||||
umask: context.umask,
|
||||
status: context.status.clone(),
|
||||
status_reason: context.status_reason,
|
||||
running: context.running,
|
||||
cpu_id: context.cpu_id,
|
||||
cpu_time: context.cpu_time,
|
||||
sched_affinity: context.sched_affinity,
|
||||
syscall: context.syscall,
|
||||
name,
|
||||
files,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A context, which identifies either a process or a thread
|
||||
#[derive(Debug)]
|
||||
pub struct Context {
|
||||
@@ -517,7 +446,6 @@ impl BorrowedHtBuf {
|
||||
let slice = self.use_for_slice(raw)?.ok_or(Error::new(ENAMETOOLONG))?;
|
||||
core::str::from_utf8(slice).map_err(|_| Error::new(EINVAL))
|
||||
}
|
||||
*/
|
||||
pub unsafe fn use_for_struct<T>(&mut self) -> Result<&mut T> {
|
||||
if mem::size_of::<T>() > PAGE_SIZE || mem::align_of::<T>() > PAGE_SIZE {
|
||||
return Err(Error::new(EINVAL));
|
||||
@@ -525,6 +453,7 @@ impl BorrowedHtBuf {
|
||||
self.buf_mut().fill(0_u8);
|
||||
Ok(unsafe { &mut *self.buf_mut().as_mut_ptr().cast() })
|
||||
}
|
||||
*/
|
||||
}
|
||||
impl Drop for BorrowedHtBuf {
|
||||
fn drop(&mut self) {
|
||||
|
||||
+3
-22
@@ -443,9 +443,6 @@ impl PageSpan {
|
||||
pub fn intersects(&self, with: PageSpan) -> bool {
|
||||
!self.intersection(with).is_empty()
|
||||
}
|
||||
pub fn contains(&self, page: Page) -> bool {
|
||||
self.intersects(Self::new(page, 1))
|
||||
}
|
||||
pub fn slice(&self, inner_span: PageSpan) -> (Option<PageSpan>, PageSpan, Option<PageSpan>) {
|
||||
(self.before(inner_span), inner_span, self.after(inner_span))
|
||||
}
|
||||
@@ -481,11 +478,6 @@ impl PageSpan {
|
||||
end.start_address().data().saturating_sub(start.start_address().data()) / PAGE_SIZE,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn rebase(self, new_base: Self, page: Page) -> Page {
|
||||
let offset = page.offset_from(self.base);
|
||||
new_base.base.next_by(offset)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for UserGrants {
|
||||
@@ -515,14 +507,6 @@ impl UserGrants {
|
||||
.filter(|(base, info)| (**base..base.next_by(info.page_count)).contains(&page))
|
||||
.map(|(base, info)| (*base, info))
|
||||
}
|
||||
// TODO: Deduplicate code?
|
||||
pub fn contains_mut(&mut self, page: Page) -> Option<(Page, &mut GrantInfo)> {
|
||||
self.inner
|
||||
.range_mut(..=page)
|
||||
.next_back()
|
||||
.filter(|(base, info)| (**base..base.next_by(info.page_count)).contains(&page))
|
||||
.map(|(base, info)| (*base, info))
|
||||
}
|
||||
/// Returns an iterator over all grants that occupy some part of the
|
||||
/// requested region
|
||||
pub fn conflicts(&self, span: PageSpan) -> impl Iterator<Item = (Page, &'_ GrantInfo)> + '_ {
|
||||
@@ -897,7 +881,6 @@ impl Grant {
|
||||
new_cow_frame
|
||||
}
|
||||
Err(AddRefError::SharedToCow) => unreachable!(),
|
||||
Err(AddRefError::RcOverflow) => return Err(Error::new(ENOMEM)),
|
||||
}
|
||||
} else { frame };
|
||||
|
||||
@@ -1062,7 +1045,6 @@ impl Grant {
|
||||
|
||||
match src_page_info.add_ref(rk) {
|
||||
Ok(()) => src_frame,
|
||||
Err(AddRefError::RcOverflow) => return Err(Enomem),
|
||||
Err(AddRefError::CowToShared) => {
|
||||
let new_frame = cow(src_frame, src_page_info, rk).map_err(|_| Enomem)?;
|
||||
|
||||
@@ -1286,7 +1268,7 @@ impl Grant {
|
||||
description: Arc::clone(&file_ref.description),
|
||||
},
|
||||
pin_refcount: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -1444,12 +1426,12 @@ pub fn setup_new_utable() -> Result<Table> {
|
||||
pub fn setup_new_utable() -> Result<Table> {
|
||||
use crate::paging::KernelMapper;
|
||||
|
||||
let mut utable = unsafe { PageMapper::create(TableKind::User, crate::rmm::FRAME_ALLOCATOR).ok_or(Error::new(ENOMEM))? };
|
||||
let utable = unsafe { PageMapper::create(TableKind::User, crate::rmm::FRAME_ALLOCATOR).ok_or(Error::new(ENOMEM))? };
|
||||
|
||||
{
|
||||
let active_ktable = KernelMapper::lock();
|
||||
|
||||
let mut copy_mapping = |p4_no| unsafe {
|
||||
let copy_mapping = |p4_no| unsafe {
|
||||
let entry = active_ktable.table().entry(p4_no)
|
||||
.unwrap_or_else(|| panic!("expected kernel PML {} to be mapped", p4_no));
|
||||
|
||||
@@ -1710,7 +1692,6 @@ fn correct_inner<'l>(addr_space_lock: &'l Arc<RwLock<AddrSpace>>, mut addr_space
|
||||
|
||||
match info.add_ref(RefKind::Shared) {
|
||||
Ok(()) => src_frame,
|
||||
Err(AddRefError::RcOverflow) => return Err(PfError::Oom),
|
||||
Err(AddRefError::CowToShared) => {
|
||||
let new_frame = cow(src_frame, info, RefKind::Shared)?;
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ use crate::paging::{RmmA, RmmArch, TableKind};
|
||||
use crate::percpu::PercpuBlock;
|
||||
use crate::syscall::error::{Error, ESRCH, Result};
|
||||
|
||||
pub use self::context::{BorrowedHtBuf, Context, ContextId, ContextSnapshot, Status, WaitpidKey};
|
||||
pub use self::context::{BorrowedHtBuf, Context, ContextId, Status, WaitpidKey};
|
||||
pub use self::list::ContextList;
|
||||
pub use self::switch::switch;
|
||||
|
||||
|
||||
-24
@@ -45,14 +45,6 @@ impl<'a> Elf<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn segments(&'a self) -> ElfSegments<'a> {
|
||||
ElfSegments {
|
||||
data: self.data,
|
||||
header: self.header,
|
||||
i: 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn symbols(&'a self) -> Option<ElfSymbols<'a>> {
|
||||
let mut symtab_opt = None;
|
||||
for section in self.sections() {
|
||||
@@ -72,22 +64,6 @@ impl<'a> Elf<'a> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the entry field of the header
|
||||
pub fn entry(&self) -> usize {
|
||||
self.header.e_entry as usize
|
||||
}
|
||||
|
||||
/// Get the program header offset
|
||||
pub fn program_headers(&self) -> usize {
|
||||
self.header.e_phoff as usize
|
||||
}
|
||||
pub fn program_header_count(&self) -> usize {
|
||||
self.header.e_phnum as usize
|
||||
}
|
||||
pub fn program_headers_size(&self) -> usize {
|
||||
self.header.e_phentsize as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ElfSections<'a> {
|
||||
|
||||
@@ -157,12 +157,6 @@ pub struct RaiiFrame {
|
||||
inner: Frame,
|
||||
}
|
||||
impl RaiiFrame {
|
||||
// TODO: Unsafe?
|
||||
pub fn new(frame: Frame) -> Self {
|
||||
Self {
|
||||
inner: frame,
|
||||
}
|
||||
}
|
||||
pub fn allocate() -> Result<Self, Enomem> {
|
||||
// TODO: Use special tag?
|
||||
init_frame(RefCount::One).map_err(|_| Enomem).map(|inner| Self { inner })
|
||||
@@ -170,11 +164,6 @@ impl RaiiFrame {
|
||||
pub fn get(&self) -> Frame {
|
||||
self.inner
|
||||
}
|
||||
pub fn take_ownership(self) -> Frame {
|
||||
let frame = self.inner.clone();
|
||||
core::mem::forget(self);
|
||||
frame
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RaiiFrame {
|
||||
@@ -336,7 +325,6 @@ pub fn init_mm() {
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum AddRefError {
|
||||
RcOverflow,
|
||||
CowToShared,
|
||||
SharedToCow,
|
||||
}
|
||||
|
||||
@@ -199,10 +199,6 @@ impl SchemeList {
|
||||
Ok(to)
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> ::alloc::collections::btree_map::Iter<SchemeId, Arc<dyn KernelScheme>> {
|
||||
self.map.iter()
|
||||
}
|
||||
|
||||
pub fn iter_name(&self, ns: SchemeNamespace) -> SchemeIter {
|
||||
SchemeIter {
|
||||
inner: self.names.get(&ns).map(|names| names.iter())
|
||||
|
||||
@@ -20,29 +20,6 @@ impl<T> WaitQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
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, reason: &'static str) -> Option<T> {
|
||||
loop {
|
||||
let mut inner = self.inner.lock();
|
||||
if let Some(value) = inner.pop_front() {
|
||||
return Some(value);
|
||||
}
|
||||
if ! self.condition.wait(inner, reason) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn receive_into_user(&self, buf: UserSliceWo, block: bool, reason: &'static str) -> Result<usize> {
|
||||
loop {
|
||||
let mut inner = self.inner.lock();
|
||||
@@ -79,29 +56,6 @@ impl<T> WaitQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn receive_into(&self, buf: &mut [T], block: bool, reason: &'static str) -> Option<usize> {
|
||||
let mut i = 0;
|
||||
|
||||
if i < buf.len() && block {
|
||||
buf[i] = self.receive(reason)?;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
{
|
||||
let mut inner = self.inner.lock();
|
||||
while i < buf.len() {
|
||||
if let Some(value) = inner.pop_front() {
|
||||
buf[i] = value;
|
||||
i += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(i)
|
||||
}
|
||||
|
||||
pub fn send(&self, value: T) -> usize {
|
||||
let len = {
|
||||
let mut inner = self.inner.lock();
|
||||
@@ -111,14 +65,4 @@ impl<T> WaitQueue<T> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user