Skip to content

Commit e0492f2

Browse files
committed
Add mutex to guard clang-rs usage
1 parent cdcdc2a commit e0492f2

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

Cargo.lock

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ boa_parser = "0.17.3"
2828
boa_interner = "0.17.3"
2929
boa_ast = "0.17.3"
3030
full_moon = "0.18.1"
31+
once_cell = "1.20.2"

core/src/lang/tokenizer/cpp.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ use clang::token::TokenKind;
55
use std::{
66
hash::{Hash, Hasher},
77
path::Path,
8+
sync::Mutex
89
};
910
use tempfile::tempdir;
11+
use once_cell::sync::Lazy;
12+
13+
static CLANG_LOCK: Lazy<Mutex<()>> = Lazy::new(|| {
14+
Mutex::new(())
15+
});
1016

1117
pub struct Cpp;
1218

@@ -21,6 +27,8 @@ impl Tokenize for Cpp {
2127
}
2228

2329
fn tokenize(path: &Path) -> anyhow::Result<Vec<Token>> {
30+
// clang-rs only allows single thread usage
31+
let _guard = CLANG_LOCK.lock().unwrap();
2432
let clang = clang::Clang::new().map_err(|err| anyhow!("{}", err))?;
2533
let index = clang::Index::new(&clang, true, false);
2634
let tu = index.parser(path).parse()?;

0 commit comments

Comments
 (0)