replace mutex with rwlock
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
c7d0bba928
commit
e055f26e90
5 changed files with 72 additions and 54 deletions
12
src/sym.rs
12
src/sym.rs
|
|
@ -18,14 +18,14 @@
|
|||
use crate::eval::eval;
|
||||
use crate::segment::{Seg, Ctr, Type};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::RwLock;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
pub type SymTable = HashMap<String, Symbol>;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref SYM_TABLE: Mutex<SymTable> = {
|
||||
Mutex::new(SymTable::new())
|
||||
pub static ref SYM_TABLE: RwLock<SymTable> = {
|
||||
RwLock::new(SymTable::new())
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ impl Symbol {
|
|||
|
||||
// Prep var table for function execution
|
||||
for n in 0..f.arg_syms.len() {
|
||||
if let Some(old) = SYM_TABLE.lock().unwrap()
|
||||
if let Some(old) = SYM_TABLE.write().unwrap()
|
||||
.insert(f.arg_syms[n].clone(), Symbol{
|
||||
name: f.arg_syms[n].clone(),
|
||||
value: ValueType::VarForm(Box::new(args[n].clone())),
|
||||
|
|
@ -206,9 +206,9 @@ impl Symbol {
|
|||
|
||||
// clear local vars and restore previous values
|
||||
for n in 0..f.arg_syms.len() {
|
||||
SYM_TABLE.lock().unwrap().remove(&f.arg_syms[n]);
|
||||
SYM_TABLE.write().unwrap().remove(&f.arg_syms[n]);
|
||||
if let Some(val) = holding_table.remove(&f.arg_syms[n]) {
|
||||
SYM_TABLE.lock().unwrap().insert(f.arg_syms[n].clone(), val);
|
||||
SYM_TABLE.write().unwrap().insert(f.arg_syms[n].clone(), val);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue