diff --git a/src/runtime2/runtime.rs b/src/runtime2/runtime.rs index 5b093be34c844f31be546b7853789b2f815dfe50..f3c46ebbe11ba125623ae42974df250a3e758ddc 100644 --- a/src/runtime2/runtime.rs +++ b/src/runtime2/runtime.rs @@ -158,7 +158,8 @@ pub struct Runtime { } impl Runtime { - pub fn new(num_threads: u32, protocol_description: ProtocolDescription) -> Runtime { + // TODO: debug_logging should be removed at some point + pub fn new(num_threads: u32, debug_logging: bool, protocol_description: ProtocolDescription) -> Runtime { assert!(num_threads > 0, "need a thread to perform work"); let runtime_inner = Arc::new(RuntimeInner { protocol: protocol_description, @@ -173,7 +174,7 @@ impl Runtime { }; for thread_index in 0..num_threads { - let mut scheduler = Scheduler::new(runtime.inner.clone(), thread_index); + let mut scheduler = Scheduler::new(runtime.inner.clone(), thread_index, debug_logging); let thread_handle = std::thread::spawn(move || { scheduler.run(); }); @@ -183,6 +184,20 @@ impl Runtime { return runtime; } + + pub fn create_component(&self, module_name: &[u8], routine_name: &[u8]) -> Result<(), ComponentCreationError> { + use crate::protocol::eval::ValueGroup; + let prompt = self.inner.protocol.new_component( + module_name, routine_name, + ValueGroup::new_stack(Vec::new()) + )?; + let reserved = self.inner.start_create_pdl_component(); + let ctx = CompCtx::new(&reserved); + let (key, _) = self.inner.finish_create_pdl_component(reserved, CompPDL::new(prompt, 0), ctx, false); + self.inner.enqueue_work(key); + + return Ok(()) + } } impl Drop for Runtime { @@ -259,33 +274,6 @@ impl RuntimeInner { return (CompKey(index), component); } - /// Creates a new component. Note that the public part will be properly - /// initialized, but not all private fields are. - pub(crate) fn create_pdl_component(&self, comp: CompPDL, ctx: CompCtx, initially_sleeping: bool) -> (CompKey, &mut RuntimeComp) { - let inbox_queue = QueueDynMpsc::new(16); - let inbox_producer = inbox_queue.producer(); - let comp = RuntimeComp{ - public: CompPublic{ - sleeping: AtomicBool::new(initially_sleeping), - num_handles: AtomicU32::new(1), // the component itself acts like a handle - inbox: inbox_producer, - }, - code: comp, - ctx, - inbox: inbox_queue, - exiting: false, - }; - - let index = self.components.create(comp); - - // TODO: just do a reserve_index followed by a consume_index or something - self.increment_active_components(); - let component = self.components.get_mut(index); - component.ctx.id = CompId(index); - - return (CompKey(index), component); - } - pub(crate) fn get_component(&self, key: CompKey) -> &mut RuntimeComp { let component = self.components.get_mut(key.0); return component;