Skip to content

Commit

Permalink
feat: Added is_loaded function to mnn-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
uttarayan21 committed Nov 20, 2024
1 parent ecd4120 commit f1c994e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@

devShells = {
default = pkgs.mkShell {
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
packages = with pkgs;
[
mnn
Expand Down
23 changes: 23 additions & 0 deletions mnn-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub enum CallbackEnum {
Callback(Callback),
Unload(oneshot::Sender<Result<()>>),
Load(oneshot::Sender<Result<()>>),
Status(oneshot::Sender<bool>),
Close,
}
type CallbackSender = CallbackEnum;
Expand Down Expand Up @@ -189,6 +190,10 @@ impl SessionState {
pub fn unload(&mut self) -> Result<()> {
self.sr.unload()
}

pub fn is_loaded(&self) -> bool {
self.sr.is_loaded()
}
}

#[non_exhaustive]
Expand Down Expand Up @@ -319,6 +324,13 @@ impl SessionHandle {
.change_context(ErrorKind::SyncError)
.attach_printable("Internal Error: Failed to send load message")?;
}

CallbackEnum::Status(tx) => {
let res = ss.is_loaded();
tx.send(res)
.change_context(ErrorKind::SyncError)
.attach_printable("Internal Error: Failed to send status message")?;
}
CallbackEnum::Close => {
break;
}
Expand Down Expand Up @@ -435,6 +447,17 @@ impl SessionHandle {
.attach_printable("Internal Error: Failed to recv load message")?
}

pub fn is_loaded(&self) -> Result<bool> {
let (tx, rx) = oneshot::channel();
self.sender
.send(CallbackEnum::Status(tx))
.map_err(|e| Report::new(ErrorKind::SyncError).attach_printable(e.to_string()))?;
Ok(rx
.recv()
.change_context(ErrorKind::SyncError)
.attach_printable("Internal Error: Failed to recv status message")?)
}

pub fn close(&self) -> Result<()> {
self.sender
.send(CallbackEnum::Close)
Expand Down

0 comments on commit f1c994e

Please sign in to comment.