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> |
45#include <csignal> |
46#include <cstring> |
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 |
228void 229PollQueue::setupAsyncIO(int fd, bool set) 230{ |
231 int flags = fcntlHelper(fd, F_GETFL); |
232 233 if (set) 234 flags |= FASYNC; 235 else 236 flags &= ~(FASYNC); 237 |
238 if (set) 239 fcntlHelper(fd, F_SETOWN, getpid()); |
240 |
241 fcntlHelper(fd, F_SETFL, flags); |
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} |