summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas@sandberg.pp.se>2013-11-29 14:36:10 +0100
committerAndreas Sandberg <andreas@sandberg.pp.se>2013-11-29 14:36:10 +0100
commitc033ead992a4e7bd8d031f25f3fa1256532c0540 (patch)
treeb66732c44d91033ef6e01ddf61705b738fc5a151 /src/base
parent9c57d5b5a66df60f77d1209f6660e4986da4bf8e (diff)
downloadgem5-c033ead992a4e7bd8d031f25f3fa1256532c0540.tar.xz
base: Fix race in PollQueue and remove SIGALRM workaround
There is a race between enabling asynchronous IO for a file descriptor and IO events happening on that descriptor. A SIGIO won't normally be delivered if an event is pending when asynchronous IO is enabled. Instead, the signal will be raised the next time there is an event on the FD. This changeset simulates a SIGIO by setting the async_io flag when setting up asynchronous IO for an FD. This causes the main event loop to poll all file descriptors to check for pending IO. As a consequence of this, the old SIGALRM hack should no longer be needed and is therefore removed.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/pollevent.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/base/pollevent.cc b/src/base/pollevent.cc
index 67e97f98f..9ed6df4fe 100644
--- a/src/base/pollevent.cc
+++ b/src/base/pollevent.cc
@@ -214,4 +214,14 @@ PollQueue::setupAsyncIO(int fd, bool set)
if (fcntl(fd, F_SETFL, flags) == -1)
panic("Could not set up async IO");
+
+ // The file descriptor might already have events pending. We won't
+ // see them if they occurred before we set the FASYNC
+ // flag. Simulate a SIGIO to ensure that the FD will be polled in
+ // next iteration of the simulation loop. We could just poll it,
+ // but this is much simpler.
+ if (set) {
+ async_event = true;
+ async_io = true;
+ }
}