-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use target connections as contexts. #465
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ConnectionBase: | ||
|
||
def __init__(self): | ||
self.target = None | ||
self._old_conn = None | ||
|
||
def __enter__(self): | ||
self._old_conn = self.target.set_connection(self) | ||
return self.target | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
self.target.set_connection(self._old_conn) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,8 @@ to be used target is also specified on instantiation by `conn_cls` parameter, | |
though all concrete :class:`Target` implementations will set an appropriate | ||
default, so there is typically no need to specify this explicitly. | ||
|
||
:class:`Connection` classes are not a part of an inheritance hierarchy, i.e. | ||
they do not derive from a common base. Instead, a :class:`Connection` is any | ||
class that implements the following methods. | ||
:class:`Connection` classes derive from | ||
:class:`devlib.conneciton.ConnectionBase` and implement the following methods. | ||
|
||
|
||
.. method:: push(self, source, dest, timeout=None) | ||
|
@@ -249,3 +248,35 @@ The only methods discussed below are those that will be overwritten by the | |
.. method:: _wait_for_boot(self) | ||
|
||
Wait for the gem5 simulated system to have booted and finished the booting animation. | ||
|
||
|
||
.. _multiple-connections: | ||
|
||
Multipe Connections With One Target | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth adding a note somewhere that Gem5Connections and TelnetConnections do not support this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I'll add a note for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which case for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes. Good catch. Fixed. |
||
----------------------------------- | ||
|
||
.. note:: Multiple parallel connections to the same target are currently not possible | ||
with ``Gem5Connection``. | ||
|
||
A ``Target`` will automatically maintain one connection per active thread and | ||
will seemlessly switch between them, so that target commands being executed from | ||
parallel threads won't block each other. | ||
|
||
It is also possible to create additional connection objects within the same | ||
thread. You can then use these connections as context managers to execute | ||
target commands using them rather than the default conection for the thread: | ||
|
||
``` | ||
conn = target.get_connection() | ||
with conn: | ||
target.execute('ls') # uses conn rather than the default connection. | ||
``` | ||
|
||
If the connection object is being used within another function, you do not need | ||
to pass the target into that function as well, as the target will be returned on | ||
entering the connection's context: | ||
|
||
``` | ||
with conn as target: | ||
target.execute('ls') | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the info on line 19 about a common base?