void release(Object p) { coroutine self = find_self(this.coroutines); coroutine blocked = this.coroutines.Find(c => c.port == p); if (blocked == null) { if (self != null) { Debug.WriteLine("[" + self.id + "] skip block"); } this.skip_block.Add(p); return; } Debug.WriteLine("[" + blocked.id + "] unblock"); Debug.WriteLine("[" + self.id + "] released"); self.released = true; this.switch_context = () => { blocked.port = null; Debug.WriteLine("[" + self.id + "] switch from"); Debug.WriteLine("[" + blocked.id + "] to"); self.yield_to(blocked); }; }
public void block(Object p) { int skip = this.skip_block.FindIndex(o => o == p); if (skip != -1) { this.skip_block.RemoveAt(skip); return; } coroutine self = find_self(this.coroutines); self.port = p; Debug.WriteLine("[" + self.id + "] block"); create_context(); self.yield_to(this.coroutines.Last()); Debug.WriteLine("[" + self.id + "] re-entered context"); Debug.Write("routines: "); foreach (coroutine c in this.coroutines) { Debug.Write(c.id + " "); } Debug.WriteLine(""); this.coroutines.RemoveAll((c) => { if (!c.finished) { return(false); } Debug.WriteLine("[" + c.id + "] removing"); c.Dispose(); return(true); }); }
public void collateral_block() { coroutine self = find_self(this.coroutines); Debug.WriteLine("[" + self.id + "] collateral_block"); this.collateral_blocked.Add(self); this.coroutines.Remove(self); create_context(); self.yield_to(this.coroutines.Last()); Debug.WriteLine("[" + self.id + "] collateral_unblock"); }
public void collateral_release(coroutine self) { if (this.collateral_blocked.Count != 0) { finish(coroutines); } while (this.collateral_blocked.Count != 0) { this.coroutines.Add(this.collateral_blocked[0]); this.collateral_blocked.RemoveAt(0); self.yield_to(this.coroutines.Last()); } }