pollevent.hh revision 10905:a6ca6831e775
19171Snilay@cs.wisc.edu/*
29171Snilay@cs.wisc.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan
39171Snilay@cs.wisc.edu * All rights reserved.
49171Snilay@cs.wisc.edu *
59171Snilay@cs.wisc.edu * Redistribution and use in source and binary forms, with or without
69171Snilay@cs.wisc.edu * modification, are permitted provided that the following conditions are
79171Snilay@cs.wisc.edu * met: redistributions of source code must retain the above copyright
89171Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer;
99171Snilay@cs.wisc.edu * redistributions in binary form must reproduce the above copyright
109171Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the
119171Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution;
129171Snilay@cs.wisc.edu * neither the name of the copyright holders nor the names of its
139171Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from
149171Snilay@cs.wisc.edu * this software without specific prior written permission.
159171Snilay@cs.wisc.edu *
169171Snilay@cs.wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
179171Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
189171Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
199171Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
209171Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
219171Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
229171Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239171Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249171Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259171Snilay@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
269171Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279171Snilay@cs.wisc.edu *
289171Snilay@cs.wisc.edu * Authors: Nathan Binkert
299171Snilay@cs.wisc.edu */
309171Snilay@cs.wisc.edu
3110123Snilay@cs.wisc.edu#ifndef __POLLEVENT_H__
3210123Snilay@cs.wisc.edu#define __POLLEVENT_H__
339171Snilay@cs.wisc.edu
349499Snilay@cs.wisc.edu#include <poll.h>
359171Snilay@cs.wisc.edu
369600Snilay@cs.wisc.edu#include <vector>
379171Snilay@cs.wisc.edu
389171Snilay@cs.wisc.edu#include "sim/core.hh"
399171Snilay@cs.wisc.edu
409600Snilay@cs.wisc.educlass Checkpoint;
419171Snilay@cs.wisc.educlass PollQueue;
429171Snilay@cs.wisc.edu
439171Snilay@cs.wisc.educlass PollEvent : public Serializable
449171Snilay@cs.wisc.edu{
459171Snilay@cs.wisc.edu  private:
469171Snilay@cs.wisc.edu    friend class PollQueue;
479171Snilay@cs.wisc.edu
4810123Snilay@cs.wisc.edu  protected:
4910123Snilay@cs.wisc.edu    pollfd pfd;
5010123Snilay@cs.wisc.edu    PollQueue *queue;
5110123Snilay@cs.wisc.edu    bool enabled;
5210123Snilay@cs.wisc.edu
539171Snilay@cs.wisc.edu  public:
54    PollEvent(int fd, int event);
55    virtual ~PollEvent();
56
57    void disable();
58    void enable();
59    virtual void process(int revent) = 0;
60
61    bool queued() { return queue != 0; }
62
63    void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
64    void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
65};
66
67class PollQueue
68{
69  private:
70    typedef std::vector<PollEvent *> eventvec_t;
71    eventvec_t events;
72
73    pollfd *poll_fds;
74    int max_size;
75    int num_fds;
76
77  public:
78    PollQueue();
79    ~PollQueue();
80
81    void copy();
82    void remove(PollEvent *event);
83    void schedule(PollEvent *event);
84    void service();
85
86  public:
87    static void setupAsyncIO(int fd, bool set);
88};
89
90extern PollQueue pollQueue;
91
92#endif // __POLLEVENT_H__
93