Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit17d1199

Browse files
authored
Lock antidote (#337)
1 parent491d7c3 commit17d1199

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
fnpredict(project_name:&str,features:Vec<f32>) ->f32{
247-
letmut projects =PROJECT_NAME_TO_PROJECT_ID.lock().unwrap();
247+
letmut 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-
usestd::sync::Mutex;
9+
useparking_lot::Mutex;
1010
use xgboost::{Booster,DMatrix};
1111

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

2626
#[pg_extern]
2727
fnmodel_predict(model_id:i64,features:Vec<f32>) ->f32{
28-
letmut guard =MODELS.lock().unwrap();
28+
letmut 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
fnmodel_predict_batch(model_id:i64,features:Vec<f32>,num_rows:i32) ->Vec<f32>{
62-
letmut guard =MODELS.lock().unwrap();
62+
letmut 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-
usestd::sync::Mutex;
5+
useparking_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
pubfnfind_deployed_estimator_by_model_id(model_id:i64) ->Arc<Box<dynEstimator>>{
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
ifletSome(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-
letmut estimators =DEPLOYED_ESTIMATORS_BY_MODEL_ID.lock().unwrap();
91+
letmut 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)

[8]ページ先頭

©2009-2025 Movatter.jp