pollevent.cc (11793:ef606668d247) pollevent.cc (12164:6a4fd7d604b1)
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 27 unchanged lines hidden (view full) ---

36
37#endif
38
39#include "base/pollevent.hh"
40
41#include <fcntl.h>
42#include <unistd.h>
43
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 27 unchanged lines hidden (view full) ---

36
37#endif
38
39#include "base/pollevent.hh"
40
41#include <fcntl.h>
42#include <unistd.h>
43
44#include <cerrno>
44#include <csignal>
45#include <csignal>
46#include <cstring>
45
46#include "base/misc.hh"
47#include "base/types.hh"
48#include "sim/async.hh"
49#include "sim/core.hh"
50#include "sim/eventq.hh"
51#include "sim/serialize.hh"
52

--- 142 unchanged lines hidden (view full) ---

195 if (revents) {
196 events[i]->process(revents);
197 if (--ret <= 0)
198 break;
199 }
200 }
201}
202
47
48#include "base/misc.hh"
49#include "base/types.hh"
50#include "sim/async.hh"
51#include "sim/core.hh"
52#include "sim/eventq.hh"
53#include "sim/serialize.hh"
54

--- 142 unchanged lines hidden (view full) ---

197 if (revents) {
198 events[i]->process(revents);
199 if (--ret <= 0)
200 break;
201 }
202 }
203}
204
205template <class ArgT>
206static int fcntlHelper(int fd, int cmd, ArgT arg)
207{
208 int retval = fcntl(fd, cmd, arg);
209 if (retval == -1) {
210 char *errstr = strerror(errno);
211 panic("fcntl(%d, %d, %s): \"%s\" when setting up async IO.\n",
212 errstr, fd, cmd, arg);
213 }
214 return retval;
215}
216
217static int fcntlHelper(int fd, int cmd)
218{
219 int retval = fcntl(fd, cmd);
220 if (retval == -1) {
221 char *errstr = strerror(errno);
222 panic("fcntl(%d, %d): \"%s\" when setting up async IO.\n",
223 errstr, fd, cmd);
224 }
225 return retval;
226}
227
203void
204PollQueue::setupAsyncIO(int fd, bool set)
205{
228void
229PollQueue::setupAsyncIO(int fd, bool set)
230{
206 int flags = fcntl(fd, F_GETFL);
207 if (flags == -1)
208 panic("Could not set up async IO");
231 int flags = fcntlHelper(fd, F_GETFL);
209
210 if (set)
211 flags |= FASYNC;
212 else
213 flags &= ~(FASYNC);
214
232
233 if (set)
234 flags |= FASYNC;
235 else
236 flags &= ~(FASYNC);
237
215 if (set) {
216 if (fcntl(fd, F_SETOWN, getpid()) == -1)
217 panic("Could not set up async IO");
218 }
238 if (set)
239 fcntlHelper(fd, F_SETOWN, getpid());
219
240
220 if (fcntl(fd, F_SETFL, flags) == -1)
221 panic("Could not set up async IO");
241 fcntlHelper(fd, F_SETFL, flags);
222
223 // The file descriptor might already have events pending. We won't
224 // see them if they occurred before we set the FASYNC
225 // flag. Simulate a SIGIO to ensure that the FD will be polled in
226 // next iteration of the simulation loop. We could just poll it,
227 // but this is much simpler.
228 if (set) {
229 async_event = true;
230 async_io = true;
231 /* Wake up some event queue to handle event */
232 getEventQueue(0)->wakeup();
233 }
234}
242
243 // The file descriptor might already have events pending. We won't
244 // see them if they occurred before we set the FASYNC
245 // flag. Simulate a SIGIO to ensure that the FD will be polled in
246 // next iteration of the simulation loop. We could just poll it,
247 // but this is much simpler.
248 if (set) {
249 async_event = true;
250 async_io = true;
251 /* Wake up some event queue to handle event */
252 getEventQueue(0)->wakeup();
253 }
254}