bb_ops/syscalls/clock_rng/
sleep.rs1use bb_ir::proto::onnx::NodeProto;
5use bb_runtime::atomic::DispatchResult;
6use bb_runtime::bus::OpError;
7use bb_runtime::framework::TimerKind;
8use bb_runtime::runtime::RuntimeResourceRef;
9use bb_runtime::slot_value::SlotValue;
10
11pub struct SleepOp;
13
14pub const DOMAIN: &str = "ai.bytesandbrains.syscall";
16pub const OP_TYPE: &str = "Sleep";
18
19pub fn invoke(
22 node: &NodeProto,
23 _inputs: &[(&str, &dyn SlotValue)],
24 ctx: &mut RuntimeResourceRef<'_>,
25) -> Result<DispatchResult, OpError> {
26 let duration_ns = node
27 .attribute
28 .iter()
29 .find(|a| a.name == "duration_ns")
30 .map(|a| a.i as u64)
31 .unwrap_or(0);
32 let now = ctx.time.scheduler.now_ns();
33 let cmd = ctx.allocate_command_id();
34 ctx.time
35 .scheduler
36 .schedule(now.saturating_add(duration_ns), TimerKind::Sleep(cmd));
37 Ok(DispatchResult::Async(cmd))
38}
39
40use bb_runtime::registry::OpRegistration as _BbOpsSyscallReg;
41
42inventory::submit! {
43 _BbOpsSyscallReg {
44 domain: DOMAIN,
45 op_type: OP_TYPE,
46 invoke,
47 kind: bb_runtime::registry::RegistrationKind::Syscall,
48 }
49}