Skip to content

Commit

Permalink
Merge pull request #69 from lambdaclass/mutex
Browse files Browse the repository at this point in the history
Add Mutex to avoid SIGSEGV
  • Loading branch information
JulianGCalderon authored Oct 18, 2024
2 parents b9314db + 78641a7 commit 5a8db1e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: lambdaclass/cairo_native
ref: 4355357697e9ab57ab88ae3a4282aac61455619e
ref: 4ba9e1609163c0d760f2a716244729d3116cc5ee
path: cairo_native
- name: Build Cairo Native Runtime Library
shell: bash
Expand Down
72 changes: 36 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions rpc-state-reader/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
collections::HashMap,
io::{self, Read},
path::PathBuf,
sync::{Arc, OnceLock, RwLock},
sync::{Arc, Mutex, OnceLock},
};

use cairo_lang_sierra::program::Program;
Expand All @@ -25,7 +25,7 @@ pub struct MiddleSierraContractClass {
pub entry_points_by_type: ContractEntryPoints,
}

static AOT_PROGRAM_CACHE: OnceLock<RwLock<HashMap<ClassHash, Arc<AotContractExecutor>>>> =
static AOT_PROGRAM_CACHE: OnceLock<Mutex<HashMap<ClassHash, Arc<AotContractExecutor>>>> =
OnceLock::new();

pub fn map_entry_points_by_type_legacy(
Expand Down Expand Up @@ -128,14 +128,14 @@ pub fn deserialize_transaction_json(
}

pub fn get_native_executor(program: Program, class_hash: ClassHash) -> Arc<AotContractExecutor> {
let cache_lock = AOT_PROGRAM_CACHE.get_or_init(|| RwLock::new(HashMap::new()));
let cache_lock = AOT_PROGRAM_CACHE.get_or_init(|| Mutex::new(HashMap::new()));
let mut cache = cache_lock.lock().unwrap();

let executor = cache_lock.read().unwrap().get(&class_hash).map(Arc::clone);
let executor = cache.get(&class_hash).map(Arc::clone);

match executor {
Some(executor) => executor,
None => {
let mut cache = cache_lock.write().unwrap();
let path = PathBuf::from(format!(
"compiled_programs/{}.{}",
class_hash.to_hex_string(),
Expand Down

0 comments on commit 5a8db1e

Please sign in to comment.