mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-19 06:55:18 +01:00
fix uring Sync,Sync unsafe impl
This commit is contained in:
@@ -8,6 +8,7 @@ use std::io::ErrorKind;
|
||||
use std::os::fd::AsFd;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use thiserror::Error;
|
||||
use tracing::{debug, trace};
|
||||
|
||||
@@ -35,6 +36,9 @@ pub struct UringIO {
|
||||
inner: Rc<RefCell<InnerUringIO>>,
|
||||
}
|
||||
|
||||
unsafe impl Send for UringIO {}
|
||||
unsafe impl Sync for UringIO {}
|
||||
|
||||
struct WrappedIOUring {
|
||||
ring: io_uring::IoUring,
|
||||
pending_ops: usize,
|
||||
@@ -132,7 +136,7 @@ impl WrappedIOUring {
|
||||
}
|
||||
|
||||
impl IO for UringIO {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags, direct: bool) -> Result<Rc<dyn File>> {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags, direct: bool) -> Result<Arc<dyn File>> {
|
||||
trace!("open_file(path = {})", path);
|
||||
let file = std::fs::File::options()
|
||||
.read(true)
|
||||
@@ -148,7 +152,7 @@ impl IO for UringIO {
|
||||
Err(error) => debug!("Error {error:?} returned when setting O_DIRECT flag to read file. The performance of the system may be affected"),
|
||||
}
|
||||
}
|
||||
let uring_file = Rc::new(UringFile {
|
||||
let uring_file = Arc::new(UringFile {
|
||||
io: self.inner.clone(),
|
||||
file,
|
||||
});
|
||||
@@ -203,6 +207,9 @@ pub struct UringFile {
|
||||
file: std::fs::File,
|
||||
}
|
||||
|
||||
unsafe impl Send for UringFile {}
|
||||
unsafe impl Sync for UringFile {}
|
||||
|
||||
impl File for UringFile {
|
||||
fn lock_file(&self, exclusive: bool) -> Result<()> {
|
||||
let fd = self.file.as_fd();
|
||||
@@ -260,7 +267,7 @@ impl File for UringFile {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pwrite(&self, pos: usize, buffer: Rc<RefCell<crate::Buffer>>, c: Completion) -> Result<()> {
|
||||
fn pwrite(&self, pos: usize, buffer: Arc<RefCell<crate::Buffer>>, c: Completion) -> Result<()> {
|
||||
let mut io = self.io.borrow_mut();
|
||||
let fd = io_uring::types::Fd(self.file.as_raw_fd());
|
||||
let write = {
|
||||
|
||||
@@ -172,7 +172,7 @@ impl Database {
|
||||
buffer_pool,
|
||||
)?);
|
||||
let conn = Rc::new(Connection {
|
||||
db: self.clone(),
|
||||
_db: self.clone(),
|
||||
pager: pager.clone(),
|
||||
schema: self.schema.clone(),
|
||||
header: self.header.clone(),
|
||||
@@ -239,7 +239,7 @@ pub fn maybe_init_database_file(file: &Arc<dyn File>, io: &Arc<dyn IO>) -> Resul
|
||||
}
|
||||
|
||||
pub struct Connection {
|
||||
db: Arc<Database>,
|
||||
_db: Arc<Database>,
|
||||
pager: Rc<Pager>,
|
||||
schema: Arc<RwLock<Schema>>,
|
||||
header: Arc<Mutex<DatabaseHeader>>,
|
||||
|
||||
Reference in New Issue
Block a user