Skip to content

Commit 74449eb

Browse files
committed
I admit to being a bit petrified of non-owning types but Lann promised me this would Just Work and IT DOES
Signed-off-by: itowlson <[email protected]>
1 parent 429ea75 commit 74449eb

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

crates/factor-blobstore/src/host.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,24 @@ pub trait IncomingData: Send + Sync {
6868
}
6969

7070
pub struct BlobStoreDispatch<'a> {
71-
allowed_containers: HashSet<String>,
72-
manager: Arc<dyn ContainerManager>,
71+
allowed_containers: &'a HashSet<String>,
72+
manager: &'a dyn ContainerManager,
7373
wasi_resources: &'a mut ResourceTable,
74-
containers: Arc<RwLock<Table<Arc<dyn Container>>>>,
75-
incoming_values: Arc<RwLock<Table<Box<dyn IncomingData>>>>,
76-
outgoing_values: Arc<RwLock<Table<OutgoingValue>>>,
77-
object_names: Arc<RwLock<Table<Box<dyn ObjectNames>>>>,
74+
containers: &'a RwLock<Table<Arc<dyn Container>>>,
75+
incoming_values: &'a RwLock<Table<Box<dyn IncomingData>>>,
76+
outgoing_values: &'a RwLock<Table<OutgoingValue>>,
77+
object_names: &'a RwLock<Table<Box<dyn ObjectNames>>>,
7878
}
7979

8080
impl<'a> BlobStoreDispatch<'a> {
8181
pub(crate) fn new(
82-
allowed_containers: HashSet<String>,
83-
manager: Arc<dyn ContainerManager>,
82+
allowed_containers: &'a HashSet<String>,
83+
manager: &'a dyn ContainerManager,
8484
wasi_resources: &'a mut ResourceTable,
85-
containers: Arc<RwLock<Table<Arc<dyn Container>>>>,
86-
incoming_values: Arc<RwLock<Table<Box<dyn IncomingData>>>>,
87-
outgoing_values: Arc<RwLock<Table<OutgoingValue>>>,
88-
object_names: Arc<RwLock<Table<Box<dyn ObjectNames>>>>,
85+
containers: &'a RwLock<Table<Arc<dyn Container>>>,
86+
incoming_values: &'a RwLock<Table<Box<dyn IncomingData>>>,
87+
outgoing_values: &'a RwLock<Table<OutgoingValue>>,
88+
object_names: &'a RwLock<Table<Box<dyn ObjectNames>>>,
8989
) -> Self {
9090
Self {
9191
allowed_containers,
@@ -99,7 +99,7 @@ impl<'a> BlobStoreDispatch<'a> {
9999
}
100100

101101
pub fn allowed_containers(&self) -> &HashSet<String> {
102-
&self.allowed_containers
102+
self.allowed_containers
103103
}
104104

105105
async fn take_incoming_value(

crates/factor-blobstore/src/lib.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ impl Factor for BlobStoreFactor {
7575
let closure = type_annotate(move |data| {
7676
let (state, table) = get_data_with_table(data);
7777
BlobStoreDispatch::new(
78-
state.allowed_containers.clone(),
79-
state.container_manager.clone(),
78+
&state.allowed_containers,
79+
state.container_manager.as_ref(),
8080
table,
81-
state.containers.clone(),
82-
state.incoming_values.clone(),
83-
state.outgoing_values.clone(),
84-
state.object_names.clone(),
81+
&state.containers,
82+
&state.incoming_values,
83+
&state.outgoing_values,
84+
&state.object_names,
8585
)
8686
});
8787
let linker = ctx.linker();
@@ -141,10 +141,10 @@ impl Factor for BlobStoreFactor {
141141
Ok(InstanceBuilder {
142142
container_manager: app_state.container_manager.clone(),
143143
allowed_containers,
144-
containers: Arc::new(RwLock::new(Table::new(capacity))),
145-
incoming_values: Arc::new(RwLock::new(Table::new(capacity))),
146-
object_names: Arc::new(RwLock::new(Table::new(capacity))),
147-
outgoing_values: Arc::new(RwLock::new(Table::new(capacity))),
144+
containers: RwLock::new(Table::new(capacity)),
145+
incoming_values: RwLock::new(Table::new(capacity)),
146+
object_names: RwLock::new(Table::new(capacity)),
147+
outgoing_values: RwLock::new(Table::new(capacity)),
148148
})
149149
}
150150
}
@@ -170,16 +170,12 @@ pub struct InstanceBuilder {
170170
///
171171
/// For the different interfaces to agree on their resource tables, each closure
172172
/// needs to derive the same resource table from the InstanceBuilder.
173-
/// The only* way that works is for the InstanceBuilder to set up all
174-
/// the resource tables, and Arc-RwLock them so that each clone gets
175-
/// the same one.
176-
///
177-
/// * TODO: for 'only', read 'or maybe we can do some shenanigans with borrowing
178-
/// from the InstanceBuilder/instance state'
179-
containers: Arc<RwLock<Table<Arc<dyn Container>>>>,
180-
incoming_values: Arc<RwLock<Table<Box<dyn IncomingData>>>>,
181-
outgoing_values: Arc<RwLock<Table<host::OutgoingValue>>>,
182-
object_names: Arc<RwLock<Table<Box<dyn ObjectNames>>>>,
173+
/// So the InstanceBuilder (which is also the instance state) sets up all the resource
174+
/// tables and RwLocks them, then the dispatch object borrows them.
175+
containers: RwLock<Table<Arc<dyn Container>>>,
176+
incoming_values: RwLock<Table<Box<dyn IncomingData>>>,
177+
outgoing_values: RwLock<Table<host::OutgoingValue>>,
178+
object_names: RwLock<Table<Box<dyn ObjectNames>>>,
183179
}
184180

185181
impl spin_factors::SelfInstanceBuilder for InstanceBuilder {}

0 commit comments

Comments
 (0)