From 8452579c6748a673bdd88a6a8e0f1b7695707fb7 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 3 Aug 2021 14:11:41 +0800 Subject: [PATCH] use parking_lot RwLock The std::sync::RwLock is platform dependent, and is unfair on Linux (may starve writer) --- Cargo.lock | 1 + nac3core/Cargo.toml | 1 + nac3core/src/typecheck/top_level.rs | 13 +++++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ffdf0a46..5dc26c9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -467,6 +467,7 @@ dependencies = [ "itertools", "num-bigint 0.3.2", "num-traits", + "parking_lot", "rustpython-parser", "test-case", ] diff --git a/nac3core/Cargo.toml b/nac3core/Cargo.toml index 09ebf724..e7081bf5 100644 --- a/nac3core/Cargo.toml +++ b/nac3core/Cargo.toml @@ -11,6 +11,7 @@ inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", feat rustpython-parser = { git = "https://github.com/RustPython/RustPython", branch = "master" } itertools = "0.10.1" crossbeam = "0.8.1" +parking_lot = "0.11.1" [dev-dependencies] test-case = "1.2.0" diff --git a/nac3core/src/typecheck/top_level.rs b/nac3core/src/typecheck/top_level.rs index 5d63a920..776e7cb8 100644 --- a/nac3core/src/typecheck/top_level.rs +++ b/nac3core/src/typecheck/top_level.rs @@ -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::sync::ShardedLock; +use parking_lot::RwLock; use rustpython_parser::ast::Stmt; pub struct DefinitionId(usize); @@ -45,7 +45,12 @@ pub struct CodeGenTask { } pub struct TopLevelContext { - pub definitions: Vec>, + pub definitions: Vec>, pub unifiers: Vec, pub codegen_queue: SegQueue, } + +pub struct WorkerContext { + pub unifier: Unifier, + pub top_level_ctx: Arc>, +}