Skip to content

Commit cd13097

Browse files
authored
Merge pull request #206 from k82cn/fix_ptr
fix: enhance ptr struct.
2 parents b4247bf + 6f4fe20 commit cd13097

6 files changed

Lines changed: 19 additions & 101 deletions

File tree

common/src/apis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustix::system;
2020
use ::rpc::flame::ApplicationSpec;
2121
use rpc::flame as rpc;
2222

23-
use crate::ptr::MutexPtr;
23+
use crate::MutexPtr;
2424
use crate::FlameError;
2525

2626
pub const DEFAULT_MAX_INSTANCES: u32 = 1_000_000;

common/src/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ limitations under the License.
1313

1414
pub mod apis;
1515
pub mod ctx;
16-
pub mod ptr;
1716
pub mod trace;
1817

1918
use serde_json::json;
2019
use std::collections::HashMap;
20+
use std::sync::Arc;
2121
use thiserror::Error;
2222
use time::macros::format_description;
2323
use tonic::Status;
@@ -78,21 +78,17 @@ impl From<FromEnvError> for FlameError {
7878
}
7979
}
8080

81-
#[macro_export]
82-
macro_rules! lock_ptr {
83-
( $mutex_arc:expr ) => {
84-
$mutex_arc
85-
.lock()
86-
.map_err(|_| FlameError::Internal("mutex ptr".to_string()))
87-
};
81+
pub type MutexPtr<T> = Arc<std::sync::Mutex<T>>;
82+
83+
pub fn new_ptr<T>(t: T) -> MutexPtr<T> {
84+
Arc::new(std::sync::Mutex::new(t))
8885
}
8986

9087
#[macro_export]
91-
macro_rules! lock_async_ptr {
88+
macro_rules! lock_ptr {
9289
( $mutex_arc:expr ) => {
9390
$mutex_arc
9491
.lock()
95-
.await
9692
.map_err(|_| FlameError::Internal("mutex ptr".to_string()))
9793
};
9894
}

common/src/ptr.rs

Lines changed: 0 additions & 78 deletions
This file was deleted.

session_manager/src/model/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use common::apis::{
2222
Application, ExecutorID, ExecutorState, Node, NodeState, ResourceRequirement, Session,
2323
SessionID, SessionState, Task, TaskID, TaskState,
2424
};
25-
use common::ptr::MutexPtr;
25+
use common::MutexPtr;
2626
use common::{lock_ptr, FlameError};
2727

2828
pub type SessionInfoPtr = Arc<SessionInfo>;

session_manager/src/scheduler/plugins/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::model::{ExecutorInfoPtr, NodeInfo, NodeInfoPtr, SessionInfo, SessionI
2121
use crate::scheduler::plugins::fairshare::FairShare;
2222
use crate::scheduler::Context;
2323

24-
use common::ptr::{self, MutexPtr};
24+
use common::{self, MutexPtr, new_ptr};
2525
use common::{lock_ptr, FlameError};
2626

2727
mod fairshare;
@@ -83,7 +83,7 @@ impl PluginManager {
8383
}
8484

8585
Ok(Arc::new(PluginManager {
86-
plugins: ptr::new_ptr(plugins),
86+
plugins: new_ptr(plugins),
8787
}))
8888
}
8989

session_manager/src/storage/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use common::apis::{
2222
ExecutorState, Node, NodePtr, ResourceRequirement, Session, SessionID, SessionPtr,
2323
SessionState, Task, TaskGID, TaskID, TaskInput, TaskOutput, TaskPtr, TaskResult, TaskState,
2424
};
25-
use common::ptr::{self, MutexPtr};
25+
use common::{self, MutexPtr};
2626
use common::{ctx::FlameContext, lock_ptr, trace::TraceFn, trace_fn, FlameError};
2727

2828
use crate::model::{
@@ -49,10 +49,10 @@ pub async fn new_ptr(config: &FlameContext) -> Result<StoragePtr, FlameError> {
4949
Ok(Arc::new(Storage {
5050
context: config.clone(),
5151
engine: engine::connect(&config.storage).await?,
52-
sessions: ptr::new_ptr(HashMap::new()),
53-
executors: ptr::new_ptr(HashMap::new()),
54-
nodes: ptr::new_ptr(HashMap::new()),
55-
applications: ptr::new_ptr(HashMap::new()),
52+
sessions: common::new_ptr(HashMap::new()),
53+
executors: common::new_ptr(HashMap::new()),
54+
nodes: common::new_ptr(HashMap::new()),
55+
applications: common::new_ptr(HashMap::new()),
5656
}))
5757
}
5858

@@ -133,7 +133,7 @@ impl Storage {
133133
pub async fn register_node(&self, node: &Node) -> Result<(), FlameError> {
134134
trace_fn!("Storage::register_node");
135135
let mut node_map = lock_ptr!(self.nodes)?;
136-
node_map.insert(node.name.clone(), ptr::new_ptr(node.clone()));
136+
node_map.insert(node.name.clone(), common::new_ptr(node.clone()));
137137
Ok(())
138138
}
139139

@@ -145,7 +145,7 @@ impl Storage {
145145
// trace_fn!("Storage::sync_node");
146146

147147
let mut node_map = lock_ptr!(self.nodes)?;
148-
node_map.insert(node.name.clone(), ptr::new_ptr(node.clone()));
148+
node_map.insert(node.name.clone(), common::new_ptr(node.clone()));
149149

150150
let mut res = vec![];
151151

@@ -310,7 +310,7 @@ impl Storage {
310310
let app = self.engine.register_application(name, attr).await?;
311311

312312
let mut app_map = lock_ptr!(self.applications)?;
313-
app_map.insert(app.name.clone(), ptr::new_ptr(app.clone()));
313+
app_map.insert(app.name.clone(), common::new_ptr(app.clone()));
314314

315315
Ok(())
316316
}
@@ -345,7 +345,7 @@ impl Storage {
345345
let app = self.engine.update_application(name.clone(), attr).await?;
346346

347347
let mut app_map = lock_ptr!(self.applications)?;
348-
app_map.insert(name.clone(), ptr::new_ptr(app.clone()));
348+
app_map.insert(name.clone(), common::new_ptr(app.clone()));
349349

350350
Ok(())
351351
}

0 commit comments

Comments
 (0)