mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-30 03:51:56 +00:00
track multiple writes
This commit is contained in:
committed by
Aiden McClelland
parent
0db5657b7f
commit
89b8278273
@@ -126,13 +126,13 @@ impl Trie {
|
|||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct Node {
|
struct Node {
|
||||||
readers: Vec<u64>,
|
readers: Vec<u64>,
|
||||||
writers: HashSet<u64>,
|
writers: Vec<u64>,
|
||||||
reqs: Vec<Request>,
|
reqs: Vec<Request>,
|
||||||
}
|
}
|
||||||
impl Node {
|
impl Node {
|
||||||
// true: If there are any writers, it is `id`.
|
// true: If there are any writers, it is `id`.
|
||||||
fn write_free(&self, id: u64) -> bool {
|
fn write_free(&self, id: u64) -> bool {
|
||||||
self.writers.is_empty() || (self.writers.len() == 1 && self.writers.contains(&id))
|
self.writers.is_empty() || (self.writers.iter().filter(|a| a != &&id).count() == 0)
|
||||||
}
|
}
|
||||||
// true: If there are any readers, it is `id`.
|
// true: If there are any readers, it is `id`.
|
||||||
fn read_free(&self, id: u64) -> bool {
|
fn read_free(&self, id: u64) -> bool {
|
||||||
@@ -158,7 +158,7 @@ impl Node {
|
|||||||
locks_on_lease: &mut Vec<oneshot::Receiver<LockInfo>>,
|
locks_on_lease: &mut Vec<oneshot::Receiver<LockInfo>>,
|
||||||
) -> Option<Request> {
|
) -> Option<Request> {
|
||||||
if req.lock_info.write() && self.write_available(req.lock_info.handle_id) {
|
if req.lock_info.write() && self.write_available(req.lock_info.handle_id) {
|
||||||
self.writers.insert(req.lock_info.handle_id);
|
self.writers.push(req.lock_info.handle_id);
|
||||||
req.process(locks_on_lease)
|
req.process(locks_on_lease)
|
||||||
} else if !req.lock_info.write() && self.read_available(req.lock_info.handle_id) {
|
} else if !req.lock_info.write() && self.read_available(req.lock_info.handle_id) {
|
||||||
self.readers.push(req.lock_info.handle_id);
|
self.readers.push(req.lock_info.handle_id);
|
||||||
@@ -170,7 +170,15 @@ impl Node {
|
|||||||
}
|
}
|
||||||
fn release(&mut self, mut lock_info: LockInfo) -> Option<LockInfo> {
|
fn release(&mut self, mut lock_info: LockInfo) -> Option<LockInfo> {
|
||||||
if lock_info.write() {
|
if lock_info.write() {
|
||||||
self.writers.remove(&lock_info.handle_id);
|
if let Some(idx) = self
|
||||||
|
.writers
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find(|(_, id)| id == &&lock_info.handle_id)
|
||||||
|
.map(|(idx, _)| idx)
|
||||||
|
{
|
||||||
|
self.writers.swap_remove(idx);
|
||||||
|
}
|
||||||
} else if let Some(idx) = self
|
} else if let Some(idx) = self
|
||||||
.readers
|
.readers
|
||||||
.iter()
|
.iter()
|
||||||
@@ -178,7 +186,7 @@ impl Node {
|
|||||||
.find(|(_, id)| id == &&lock_info.handle_id)
|
.find(|(_, id)| id == &&lock_info.handle_id)
|
||||||
.map(|(idx, _)| idx)
|
.map(|(idx, _)| idx)
|
||||||
{
|
{
|
||||||
self.readers.swap_remove(idx);
|
assert!(lock_info.handle_id == self.readers.swap_remove(idx));
|
||||||
}
|
}
|
||||||
if lock_info.ptr.len() == lock_info.segments_handled {
|
if lock_info.ptr.len() == lock_info.segments_handled {
|
||||||
None
|
None
|
||||||
|
|||||||
Reference in New Issue
Block a user