Files
turso/core/io/darwin.rs
Pekka Enberg ed9f3e6d1e Single-threaded architecture
Use Rc instead of Arc and replace the concurrent LRU with
single-threaded SIEVE.

Fixes #23
Fixes #29
2024-03-03 12:44:45 +02:00

47 lines
1023 B
Rust

use super::{Completion, File, IO};
use anyhow::{Ok, Result};
use std::rc::Rc;
use std::cell::RefCell;
use std::io::{Read, Seek};
use log::trace;
pub struct DarwinIO {}
impl DarwinIO {
pub fn new() -> Result<Self> {
Ok(Self {})
}
}
impl IO for DarwinIO {
fn open_file(&self, path: &str) -> Result<Box<dyn File>> {
trace!("open_file(path = {})", path);
let file = std::fs::File::open(path)?;
Ok(Box::new(DarwinFile {
file: RefCell::new(file),
}))
}
fn run_once(&self) -> Result<()> {
Ok(())
}
}
pub struct DarwinFile {
file: RefCell<std::fs::File>,
}
impl File for DarwinFile {
fn pread(&self, pos: usize, c: Rc<Completion>) -> Result<()> {
let mut file = self.file.borrow_mut();
file.seek(std::io::SeekFrom::Start(pos as u64))?;
{
let mut buf = c.buf_mut();
let buf = buf.as_mut_slice();
file.read_exact(buf)?;
}
c.complete();
Ok(())
}
}