Skip to content

Commit

Permalink
Plugins: Remove Sync bound from ByteSource Trait
Browse files Browse the repository at this point in the history
Sync trait bound is not needed inside Chipmunk and can be removed in
favor of avoiding using Mutex inside bytesource plugin since it wasm
resource table - which is used within the plugin host - doesn't
implement Sync trait.
  • Loading branch information
AmmarAbouZor committed Aug 2, 2024
1 parent 2219b0a commit a42ff83
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
16 changes: 3 additions & 13 deletions application/apps/indexer/plugins_host/src/v0_1_0/bytesource/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod bindings;
mod bytesource_plugin_state;

use std::{io, path::Path, sync::Mutex};
use std::{io, path::Path};

use bindings::BytesourcePlugin;
use bytesource_plugin_state::ByteSourcePluginState;
Expand All @@ -20,8 +20,7 @@ use crate::{
//TODO AAZ: Remove after prototyping
#[allow(unused)]
pub struct PluginByteSource {
//TODO AAZ: Check if there is a way to remove the mutex here
store: Mutex<Store<ByteSourcePluginState>>,
store: Store<ByteSourcePluginState>,
plugin_bindings: BytesourcePlugin,
}

Expand Down Expand Up @@ -96,26 +95,17 @@ impl PluginByteSource {
PluginHostInitError::GuestError(PluginGuestInitError::from(guest_err))
})?;

let store = Mutex::new(store);

Ok(Self {
store,
plugin_bindings,
})
}

pub async fn read_next(&mut self, len: usize) -> io::Result<Vec<u8>> {
let store = self.store.get_mut().map_err(|err| {
io::Error::new(
io::ErrorKind::Other,
format!("Bytesource Plugin: Poison Error while acquiring WASM store. Error: {err}"),
)
})?;

let bytes_result = self
.plugin_bindings
.chipmunk_plugin_byte_source()
.call_read(store, len as u64)
.call_read(&mut self.store, len as u64)
.await
.map_err(|err| {
io::Error::new(
Expand Down
2 changes: 1 addition & 1 deletion application/apps/indexer/sources/src/binary/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
}

#[async_trait]
impl<R: Read + Send + Sync> ByteSource for BinaryByteSource<R> {
impl<R: Read + Send> ByteSource for BinaryByteSource<R> {
async fn reload(
&mut self,
_: Option<&SourceFilter>,
Expand Down
2 changes: 1 addition & 1 deletion application/apps/indexer/sources/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub(crate) const DEFAULT_MIN_BUFFER_SPACE: usize = 10 * 1024;
/// data into an internal buffer.
/// This data can then be accessed via the `current_slice` method.
#[async_trait]
pub trait ByteSource: Send + Sync {
pub trait ByteSource: Send {
/// Indicate that we have consumed a certain amount of data from our internal
/// buffer and that this part can be discarded
fn consume(&mut self, offset: usize);
Expand Down

0 comments on commit a42ff83

Please sign in to comment.