From: Gabe Black Date: Sat, 17 Aug 2019 06:12:11 +0000 (-0700) Subject: sim: Add a takeOverFrom method to the base Port class. X-Git-Tag: v19.0.0.0~629 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=51d46ef4c69173cad68e35142715c04a5b882983;p=gem5.git sim: Add a takeOverFrom method to the base Port class. This makes it easier, safer, and less verbose to swap out ports when a CPU takes over for another CPU, for instance. Change-Id: Ice08e4dcb4b04dc66b1841331092a78b4f6f5a96 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20233 Tested-by: kokoro Reviewed-by: Jason Lowe-Power Reviewed-by: Nikos Nikoleris Reviewed-by: Andreas Sandberg Maintainer: Gabe Black --- diff --git a/src/sim/port.hh b/src/sim/port.hh index ee4b548a5..111417263 100644 --- a/src/sim/port.hh +++ b/src/sim/port.hh @@ -126,6 +126,25 @@ class Port /** Is this port currently connected to a peer? */ bool isConnected() const { return _connected; } + + /** A utility function to make it easier to swap out ports. */ + void + takeOverFrom(Port *old) + { + assert(old); + assert(old->isConnected()); + assert(!isConnected()); + Port &peer = old->getPeer(); + assert(peer.isConnected()); + + // Disconnect the original binding. + old->unbind(); + peer.unbind(); + + // Connect the new binding. + peer.bind(*this); + bind(peer); + } }; #endif //__SIM_PORT_HH__