use parking_lot RwLock

The std::sync::RwLock is platform dependent, and is unfair on Linux
(may starve writer)
This commit is contained in:
pca006132 2021-08-03 14:11:41 +08:00
parent f00c1813e3
commit 8452579c67
3 changed files with 11 additions and 4 deletions

1
Cargo.lock generated
View File

@ -467,6 +467,7 @@ dependencies = [
"itertools", "itertools",
"num-bigint 0.3.2", "num-bigint 0.3.2",
"num-traits", "num-traits",
"parking_lot",
"rustpython-parser", "rustpython-parser",
"test-case", "test-case",
] ]

View File

@ -11,6 +11,7 @@ inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", feat
rustpython-parser = { git = "https://github.com/RustPython/RustPython", branch = "master" } rustpython-parser = { git = "https://github.com/RustPython/RustPython", branch = "master" }
itertools = "0.10.1" itertools = "0.10.1"
crossbeam = "0.8.1" crossbeam = "0.8.1"
parking_lot = "0.11.1"
[dev-dependencies] [dev-dependencies]
test-case = "1.2.0" test-case = "1.2.0"

View File

@ -1,8 +1,8 @@
use std::collections::HashMap; use std::{collections::HashMap, sync::Arc};
use super::typedef::{SharedUnifier, Type}; use super::typedef::{SharedUnifier, Type, Unifier};
use crossbeam::queue::SegQueue; use crossbeam::queue::SegQueue;
use crossbeam::sync::ShardedLock; use parking_lot::RwLock;
use rustpython_parser::ast::Stmt; use rustpython_parser::ast::Stmt;
pub struct DefinitionId(usize); pub struct DefinitionId(usize);
@ -45,7 +45,12 @@ pub struct CodeGenTask {
} }
pub struct TopLevelContext { pub struct TopLevelContext {
pub definitions: Vec<ShardedLock<TopLevelDef>>, pub definitions: Vec<RwLock<TopLevelDef>>,
pub unifiers: Vec<SharedUnifier>, pub unifiers: Vec<SharedUnifier>,
pub codegen_queue: SegQueue<CodeGenTask>, pub codegen_queue: SegQueue<CodeGenTask>,
} }
pub struct WorkerContext {
pub unifier: Unifier,
pub top_level_ctx: Arc<RwLock<TopLevelContext>>,
}