Skip to content

Commit

Permalink
Remove lock of buf_vec.
Browse files Browse the repository at this point in the history
Signed-off-by: root <[email protected]>
  • Loading branch information
ustc-wxy committed Dec 8, 2022
1 parent 193b92e commit b334a08
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ where
0 => {
ctx.single_wait(0).unwrap();
LogBatch::decode_entries_block(
&ctx.data(0).lock().unwrap(),
&ctx.data(0),
ents_idx[0].entries.unwrap(),
ents_idx[0].compression_type,
)
Expand All @@ -391,7 +391,7 @@ where
seq += 1;
ctx.single_wait(seq).unwrap();
LogBatch::decode_entries_block(
&ctx.data(seq).lock().unwrap(),
&ctx.data(seq),
i.entries.unwrap(),
i.compression_type,
)
Expand Down
15 changes: 7 additions & 8 deletions src/env/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,16 @@ impl LogFd {
}

pub fn read_aio(&self, seq: usize, ctx: &mut AioContext, offset: u64) {
let mut buf = ctx.buf_vec.last().unwrap().lock().unwrap();
unsafe {
let aior = &mut ctx.aio_vec[seq];
aior.aio_fildes = self.0;
aior.aio_buf = buf.as_mut_ptr() as *mut c_void;
aior.aio_reqprio = 0;
aior.aio_sigevent = SigEvent::new(SigevNotify::SigevNone).sigevent();
aior.aio_nbytes = buf.len() as usize;
aior.aio_nbytes = ctx.buf_vec[seq].len() as usize;
aior.aio_buf = ctx.buf_vec[seq].as_mut_ptr() as *mut c_void;
aior.aio_lio_opcode = libc::LIO_READ;
aior.aio_offset = offset as off_t;
libc::aio_read(&mut ctx.aio_vec[seq]);
libc::aio_read(aior);
}
}

Expand Down Expand Up @@ -279,7 +278,7 @@ impl WriteExt for LogFile {

pub struct AioContext {
aio_vec: Vec<aiocb>,
pub(crate) buf_vec: Vec<Arc<Mutex<Vec<u8>>>>,
pub(crate) buf_vec: Vec<Vec<u8>>,
}
impl AioContext {
pub fn new(block_sum: usize) -> Self {
Expand All @@ -298,7 +297,7 @@ impl AioContext {

impl AsyncContext for AioContext {
fn single_wait(&mut self, seq: usize) -> IoResult<usize> {
let buf_len = self.buf_vec[seq].lock().unwrap().len();
let buf_len = self.buf_vec[seq].len();
unsafe {
loop {
libc::aio_suspend(
Expand All @@ -324,8 +323,8 @@ impl AsyncContext for AioContext {
Ok(total as usize)
}

fn data(&self, seq: usize) -> Arc<Mutex<Vec<u8>>> {
self.buf_vec[seq].clone()
fn data(&self, seq: usize) -> Vec<u8> {
self.buf_vec[seq].to_vec()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ pub trait WriteExt {
pub trait AsyncContext {
fn wait(&mut self) -> Result<usize>;
fn single_wait(&mut self, seq: usize) -> Result<usize>;
fn data(&self, seq: usize) -> Arc<Mutex<Vec<u8>>>;
fn data(&self, seq: usize) -> Vec<u8>;
}
3 changes: 1 addition & 2 deletions src/file_pipe_log/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ impl<F: FileSystem> SinglePipe<F> {
) -> Result<()> {
unsafe {
let fd = self.get_fd(handle.id.seq)?;
let buf = vec![0 as u8; handle.len];
let buf = Arc::new(SyncMutex::new(buf));
let mut buf = vec![0 as u8; handle.len];
ctx.buf_vec.push(buf);
self.file_system
.as_ref()
Expand Down

0 comments on commit b334a08

Please sign in to comment.