Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/11529
Change subject: base: Ensure the coroutine returns to the Fiber that called
it.
......................................................................
base: Ensure the coroutine returns to the Fiber that called it.
Instead of tracking the Fiber that created it (and where it runs the
first time), instead track the Fiber that it's called from each time
it's called.
This could be an issue if a coroutine instance is accessible from
multiple Fibers, for instance if it's an accessible member of another
class, or if it's a global instance somewhere. Then there's no
guarantee that the Fiber consuming it is the same as the one that
created it. Also, coroutines can (as far as I can tell) be passed
around by reference or pointer and called from arbitrary places.
Change-Id: Icb1766bf9ae7e4bc650c6ccd5949106414cb47d0
---
M src/base/coroutine.hh
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/src/base/coroutine.hh b/src/base/coroutine.hh
index 8e5358c..d288892 100644
--- a/src/base/coroutine.hh
+++ b/src/base/coroutine.hh
@@ -86,9 +86,7 @@
{
friend class Coroutine;
protected:
- CallerType(Coroutine& _coro)
- : coro(_coro), callerFiber(currentFiber())
- {}
+ CallerType(Coroutine& _coro) : coro(_coro), callerFiber(nullptr) {}
public:
/**
@@ -170,7 +168,7 @@
: Fiber(), task(f), caller(*this)
{
// Create and Run the Coroutine
- this->run();
+ this->call();
}
virtual ~Coroutine() {}
@@ -191,7 +189,7 @@
!std::is_same<T, void>::value, T>::type param)
{
argsChannel.push(param);
- this->run();
+ this->call();
return *this;
}
@@ -205,7 +203,7 @@
typename std::enable_if<std::is_same<T, void>::value, Coroutine>::type&
operator()()
{
- this->run();
+ this->call();
return *this;
}
@@ -225,7 +223,7 @@
{
auto& ret_channel = caller.retChannel;
while (ret_channel.empty()) {
- this->run();
+ this->call();
}
auto ret = ret_channel.top();
@@ -245,6 +243,13 @@
*/
void main() override { this->task(caller); }
+ void
+ call()
+ {
+ caller.callerFiber = currentFiber();
+ run();
+ }
+
private:
/** Arguments for the coroutine */
ArgChannel argsChannel;
--
To view, visit https://gem5-review.googlesource.com/11529
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Icb1766bf9ae7e4bc650c6ccd5949106414cb47d0
Gerrit-Change-Number: 11529
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev