diff --git a/src/runtime2/runtime.rs b/src/runtime2/runtime.rs index 8265a8c8b88e2c94d7279d3a96f3ec595a8e1b65..ffee9f5038c8faf3758730e71870b54862dccccf 100644 --- a/src/runtime2/runtime.rs +++ b/src/runtime2/runtime.rs @@ -59,7 +59,8 @@ pub(crate) struct RuntimeComp { pub public: CompPublic, pub code: CompPDL, pub ctx: CompCtx, - pub inbox: QueueDynMpsc + pub inbox: QueueDynMpsc, + pub exiting: bool, } /// Should contain everything that is accessible in a thread-safe manner @@ -109,9 +110,10 @@ impl CompHandle { /// Returns the `CompKey` to the component if it should be destroyed pub(crate) fn decrement_users(&mut self) -> Option { debug_assert!(!self.decremented, "illegal to 'decrement_users' twice"); - dbg_code!(self.decremented = true); let old_count = self.num_handles.fetch_sub(1, Ordering::AcqRel); let new_count = old_count - 1; + dbg_code!(self.decremented = true); + println!(" ****** DEBUG [handle]: Decremented count to {} for {:?}", new_count, self.id); if new_count == 0 { return Some(unsafe{ self.id.upgrade() }); } @@ -248,6 +250,7 @@ impl RuntimeInner { code: component, ctx: context, inbox: inbox_queue, + exiting: false, }; let index = self.components.submit(reserved.reservation, component); @@ -271,6 +274,7 @@ impl RuntimeInner { code: comp, ctx, inbox: inbox_queue, + exiting: false, }; let index = self.components.create(comp); @@ -294,7 +298,11 @@ impl RuntimeInner { } pub(crate) fn destroy_component(&self, key: CompKey) { - debug_assert_eq!(self.get_component(key).public.num_handles.load(Ordering::Acquire), 0); + dbg_code!({ + let component = self.get_component(key); + debug_assert!(component.exiting); + debug_assert_eq!(component.public.num_handles.load(Ordering::Acquire), 0); + }); self.decrement_active_components(); self.components.destroy(key.0); } @@ -314,7 +322,7 @@ impl RuntimeInner { if new_val == 0 { // Just to be sure, in case the last thing that gets destroyed is an // API instead of a thread. - let lock = self.work_queue.lock(); + let _lock = self.work_queue.lock(); self.work_condvar.notify_all(); } }