Skip to content

Commit

Permalink
fix(instance_man): moka cache item trigger clone when iterating
Browse files Browse the repository at this point in the history
  • Loading branch information
ActivePeter committed Jun 13, 2024
1 parent 27e08da commit 979b78d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/worker/func/m_instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ use super::shared::process_rpc::ProcessRpc;
use super::{owned::wasm, shared::SharedInstance, FnExeCtx, Instance, OwnedInstance};
use crate::general::m_os::OperatingSystem;
use crate::general::network::rpc_model;
use crate::logical_module_view_impl;
use crate::sys::LogicalModulesRef;
use crate::{
general::m_appmeta_manager::AppType, // worker::host_funcs,
result::WSResult,
sys::{LogicalModule, LogicalModuleNewArgs},
util::JoinHandleWrapper,
};
use crate::{logical_module_view_impl, util};
use async_trait::async_trait;
use crossbeam_skiplist::SkipMap;
use enum_as_inner::EnumAsInner;
use std::{
collections::{HashMap, VecDeque},
path::{Path, PathBuf},
ptr::NonNull,
sync::atomic::{AtomicU64, Ordering},
sync::{
atomic::{AtomicU64, Ordering},
Arc,
},
time::Duration,
};
use tokio::sync::Notify;
Expand Down Expand Up @@ -96,16 +99,17 @@ pub struct KvEventDef {
// // }
// }

struct InstanceCell(Option<OwnedInstance>);
impl Clone for InstanceCell {
fn clone(&self) -> Self {
Self(None)
}
}
#[derive(Clone)]
struct InstanceCell(Arc<Option<OwnedInstance>>);
// impl Clone for InstanceCell {
// fn clone(&self) -> Self {
// Self(None)
// }
// }

impl From<OwnedInstance> for InstanceCell {
fn from(a: OwnedInstance) -> Self {
Self(Some(a))
Self(Arc::new(Some(a)))
}
}

Expand Down Expand Up @@ -140,7 +144,7 @@ impl OwnedEachAppCache {

if let Some(a) = self.cache.iter().next() {
if let Some(a) = self.cache.remove(&*a.0) {
return a.0.unwrap();
return unsafe { util::non_null(&*a.0).as_mut().take().unwrap() };
}
}

Expand Down

0 comments on commit 979b78d

Please sign in to comment.