pollevent.hh revision 2665
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
342SN/A#include <vector>
352SN/A#include <poll.h>
361696SN/A#include "sim/root.hh"
372SN/A
38252SN/Aclass Checkpoint;
391872SN/Aclass PollQueue;
40252SN/A
412SN/Aclass PollEvent
422SN/A{
432SN/A  private:
442SN/A    friend class PollQueue;
452SN/A
462SN/A  protected:
472SN/A    pollfd pfd;
482SN/A    PollQueue *queue;
492SN/A    bool enabled;
502SN/A
512SN/A  public:
522SN/A    PollEvent(int fd, int event);
532SN/A    virtual ~PollEvent();
542SN/A
552SN/A    void disable();
562SN/A    void enable();
572SN/A    virtual void process(int revent) = 0;
58251SN/A
59251SN/A    bool queued() { return queue != 0; }
60252SN/A
61252SN/A    virtual void serialize(std::ostream &os);
62252SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
632SN/A};
642SN/A
652SN/Aclass PollQueue
662SN/A{
672SN/A  private:
682SN/A    typedef std::vector<PollEvent *> eventvec_t;
692SN/A    eventvec_t events;
702SN/A
712SN/A    pollfd *poll_fds;
722SN/A    int max_size;
732SN/A    int num_fds;
742SN/A
752SN/A  public:
762SN/A    PollQueue();
772SN/A    ~PollQueue();
782SN/A
792SN/A    void copy();
802SN/A    void remove(PollEvent *event);
812SN/A    void schedule(PollEvent *event);
822SN/A    void service();
832SN/A
842SN/A  protected:
852SN/A    static bool handler;
862SN/A    static struct sigaction oldio;
872SN/A    static struct sigaction oldalrm;
882SN/A
892SN/A  public:
902SN/A    static void setupAsyncIO(int fd, bool set);
912SN/A    static void handleIO(int);
922SN/A    static void handleALRM(int);
932SN/A    static void removeHandler();
942SN/A    static void setupHandler();
952SN/A};
962SN/A
972SN/Aextern PollQueue pollQueue;
982SN/A
992SN/A#endif // __POLLEVENT_H__
100