pollevent.hh revision 8229
12SN/A/* 21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 292SN/A */ 302SN/A 312SN/A#ifndef __POLLEVENT_H__ 322SN/A#define __POLLEVENT_H__ 332SN/A 348229Snate@binkert.org#include <poll.h> 358229Snate@binkert.org 362SN/A#include <vector> 378229Snate@binkert.org 384167Sbinkertn@umich.edu#include "sim/core.hh" 392SN/A 40252SN/Aclass Checkpoint; 411872SN/Aclass PollQueue; 42252SN/A 432SN/Aclass PollEvent 442SN/A{ 452SN/A private: 462SN/A friend class PollQueue; 472SN/A 482SN/A protected: 492SN/A pollfd pfd; 502SN/A PollQueue *queue; 512SN/A bool enabled; 522SN/A 532SN/A public: 542SN/A PollEvent(int fd, int event); 552SN/A virtual ~PollEvent(); 562SN/A 572SN/A void disable(); 582SN/A void enable(); 592SN/A virtual void process(int revent) = 0; 60251SN/A 61251SN/A bool queued() { return queue != 0; } 62252SN/A 63252SN/A virtual void serialize(std::ostream &os); 64252SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 652SN/A}; 662SN/A 672SN/Aclass PollQueue 682SN/A{ 692SN/A private: 702SN/A typedef std::vector<PollEvent *> eventvec_t; 712SN/A eventvec_t events; 722SN/A 732SN/A pollfd *poll_fds; 742SN/A int max_size; 752SN/A int num_fds; 762SN/A 772SN/A public: 782SN/A PollQueue(); 792SN/A ~PollQueue(); 802SN/A 812SN/A void copy(); 822SN/A void remove(PollEvent *event); 832SN/A void schedule(PollEvent *event); 842SN/A void service(); 852SN/A 862SN/A protected: 872SN/A static bool handler; 882SN/A static struct sigaction oldio; 892SN/A static struct sigaction oldalrm; 902SN/A 912SN/A public: 922SN/A static void setupAsyncIO(int fd, bool set); 932SN/A static void handleIO(int); 942SN/A static void handleALRM(int); 952SN/A static void removeHandler(); 962SN/A static void setupHandler(); 972SN/A}; 982SN/A 992SN/Aextern PollQueue pollQueue; 1002SN/A 1012SN/A#endif // __POLLEVENT_H__ 102