Skip to content

Commit

Permalink
chore: use RwLock in MemPoolStore
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Dec 11, 2021
1 parent 9fc8a91 commit 8b7f31a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions crates/store/src/mem_pool_store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, sync::Mutex};
use std::{collections::HashMap, sync::RwLock};

use gw_types::bytes::Bytes;

Expand Down Expand Up @@ -32,13 +32,13 @@ impl<T> Value<T> {
}

pub struct MemPoolStore {
inner: Vec<Mutex<HashMap<Bytes, Value<Bytes>>>>,
inner: Vec<RwLock<HashMap<Bytes, Value<Bytes>>>>,
}

impl MemPoolStore {
pub fn new(columns: usize) -> Self {
let mut mem_pool_store = Vec::default();
mem_pool_store.resize_with(columns, || Mutex::new(Default::default()));
mem_pool_store.resize_with(columns, || RwLock::new(Default::default()));
Self {
inner: mem_pool_store,
}
Expand All @@ -49,8 +49,8 @@ impl MemPoolStore {
.inner
.get(col)
.expect("col")
.lock()
.expect("mem pool store");
.read()
.expect("read mem pool store");
col.get(key).cloned()
}

Expand All @@ -59,8 +59,8 @@ impl MemPoolStore {
.inner
.get(col)
.expect("col")
.lock()
.expect("mem pool store");
.write()
.expect("write mem pool store");
col.insert(key, value);
}
}

0 comments on commit 8b7f31a

Please sign in to comment.