Skip to content

Commit 17d1199

Browse files
authored
Lock antidote (#337)
1 parent 491d7c3 commit 17d1199

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

pgml-extension/pgml_rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ rmp-serde = { version = "1.1.0" }
3131
typetag = "0.2"
3232
pyo3 = { version = "0.17", features = ["auto-initialize"] }
3333
heapless = "0.7.13"
34+
parking_lot = "0.12"
3435

3536
[dev-dependencies]
3637
pgx-tests = "=0.4.5"

pgml-extension/pgml_rust/src/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use parking_lot::Mutex;
12
use std::collections::HashMap;
23
use std::fmt::Write;
34
use std::str::FromStr;
4-
use std::sync::Mutex;
55

66
use once_cell::sync::Lazy;
77
use pgx::*;
@@ -244,7 +244,7 @@ fn deploy(
244244

245245
#[pg_extern]
246246
fn predict(project_name: &str, features: Vec<f32>) -> f32 {
247-
let mut projects = PROJECT_NAME_TO_PROJECT_ID.lock().unwrap();
247+
let mut projects = PROJECT_NAME_TO_PROJECT_ID.lock();
248248
let project_id = match projects.get(project_name) {
249249
Some(project_id) => *project_id,
250250
None => {

pgml-extension/pgml_rust/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use once_cell::sync::Lazy; // 1.3.1
66
use pgx::*;
77
use std::collections::HashMap;
88
use std::fs;
9-
use std::sync::Mutex;
9+
use parking_lot::Mutex;
1010
use xgboost::{Booster, DMatrix};
1111

1212
pub mod api;
@@ -25,7 +25,7 @@ static MODELS: Lazy<Mutex<HashMap<i64, Vec<u8>>>> = Lazy::new(|| Mutex::new(Hash
2525

2626
#[pg_extern]
2727
fn model_predict(model_id: i64, features: Vec<f32>) -> f32 {
28-
let mut guard = MODELS.lock().unwrap();
28+
let mut guard = MODELS.lock();
2929

3030
match guard.get(&model_id) {
3131
Some(data) => {
@@ -59,7 +59,7 @@ fn model_predict(model_id: i64, features: Vec<f32>) -> f32 {
5959

6060
#[pg_extern]
6161
fn model_predict_batch(model_id: i64, features: Vec<f32>, num_rows: i32) -> Vec<f32> {
62-
let mut guard = MODELS.lock().unwrap();
62+
let mut guard = MODELS.lock();
6363

6464
if num_rows < 0 {
6565
error!("Number of rows has to be greater than 0");

pgml-extension/pgml_rust/src/orm/estimator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22
use std::fmt::Debug;
33
use std::str::FromStr;
44
use std::sync::Arc;
5-
use std::sync::Mutex;
5+
use parking_lot::Mutex;
66

77
use ndarray::{Array1, Array2};
88
use once_cell::sync::Lazy;
@@ -26,7 +26,7 @@ static DEPLOYED_ESTIMATORS_BY_MODEL_ID: Lazy<Mutex<HashMap<i64, Arc<Box<dyn Esti
2626
pub fn find_deployed_estimator_by_model_id(model_id: i64) -> Arc<Box<dyn Estimator>> {
2727
// Get the estimator from process memory, if we already loaded it.
2828
{
29-
let estimators = DEPLOYED_ESTIMATORS_BY_MODEL_ID.lock().unwrap();
29+
let estimators = DEPLOYED_ESTIMATORS_BY_MODEL_ID.lock();
3030
if let Some(estimator) = estimators.get(&model_id) {
3131
return estimator.clone();
3232
}
@@ -88,7 +88,7 @@ pub fn find_deployed_estimator_by_model_id(model_id: i64) -> Arc<Box<dyn Estimat
8888
};
8989

9090
// Cache the estimator in process memory.
91-
let mut estimators = DEPLOYED_ESTIMATORS_BY_MODEL_ID.lock().unwrap();
91+
let mut estimators = DEPLOYED_ESTIMATORS_BY_MODEL_ID.lock();
9292
estimators.insert(model_id, Arc::new(estimator));
9393
estimators.get(&model_id).unwrap().clone()
9494
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy