event.hh revision 12957
112955Sgabeblack@google.com/*
212955Sgabeblack@google.com * Copyright 2018 Google, Inc.
312955Sgabeblack@google.com *
412955Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512955Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612955Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712955Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812955Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912955Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012955Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112955Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212955Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312955Sgabeblack@google.com * this software without specific prior written permission.
1412955Sgabeblack@google.com *
1512955Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612955Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712955Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812955Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912955Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012955Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112955Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212955Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312955Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412955Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512955Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612955Sgabeblack@google.com *
2712955Sgabeblack@google.com * Authors: Gabe Black
2812955Sgabeblack@google.com */
2912955Sgabeblack@google.com
3012955Sgabeblack@google.com#ifndef __SYSTEMC_CORE_EVENT_HH__
3112955Sgabeblack@google.com#define __SYSTEMC_CORE_EVENT_HH__
3212955Sgabeblack@google.com
3312957Sgabeblack@google.com#include <set>
3412955Sgabeblack@google.com#include <string>
3512955Sgabeblack@google.com#include <vector>
3612955Sgabeblack@google.com
3712957Sgabeblack@google.com#include "sim/eventq.hh"
3812955Sgabeblack@google.com#include "systemc/core/list.hh"
3912955Sgabeblack@google.com#include "systemc/core/object.hh"
4012955Sgabeblack@google.com#include "systemc/ext/core/sc_prim.hh"
4112955Sgabeblack@google.com#include "systemc/ext/core/sc_time.hh"
4212955Sgabeblack@google.com
4312955Sgabeblack@google.comnamespace sc_core
4412955Sgabeblack@google.com{
4512955Sgabeblack@google.com
4612955Sgabeblack@google.comclass sc_event;
4712955Sgabeblack@google.com
4812955Sgabeblack@google.com} // namespace sc_core
4912955Sgabeblack@google.com
5012955Sgabeblack@google.comnamespace sc_gem5
5112955Sgabeblack@google.com{
5212955Sgabeblack@google.com
5312955Sgabeblack@google.comtypedef std::vector<sc_core::sc_event *> Events;
5412955Sgabeblack@google.com
5512957Sgabeblack@google.comclass Sensitivity;
5612957Sgabeblack@google.com
5712955Sgabeblack@google.comclass Event
5812955Sgabeblack@google.com{
5912955Sgabeblack@google.com  public:
6012955Sgabeblack@google.com    Event(sc_core::sc_event *_sc_event);
6112955Sgabeblack@google.com    Event(sc_core::sc_event *_sc_event, const char *_basename);
6212955Sgabeblack@google.com
6312955Sgabeblack@google.com    ~Event();
6412955Sgabeblack@google.com
6512955Sgabeblack@google.com    sc_core::sc_event *sc_event() { return _sc_event; }
6612955Sgabeblack@google.com
6712955Sgabeblack@google.com    const std::string &name() const;
6812955Sgabeblack@google.com    const std::string &basename() const;
6912955Sgabeblack@google.com    bool inHierarchy() const;
7012955Sgabeblack@google.com    sc_core::sc_object *getParentObject() const;
7112955Sgabeblack@google.com
7212955Sgabeblack@google.com    void notify();
7312955Sgabeblack@google.com    void notify(const sc_core::sc_time &t);
7412955Sgabeblack@google.com    void
7512955Sgabeblack@google.com    notify(double d, sc_core::sc_time_unit &u)
7612955Sgabeblack@google.com    {
7712955Sgabeblack@google.com        notify(sc_core::sc_time(d, u));
7812955Sgabeblack@google.com    }
7912955Sgabeblack@google.com    void cancel();
8012955Sgabeblack@google.com
8112955Sgabeblack@google.com    bool triggered() const;
8212955Sgabeblack@google.com
8312955Sgabeblack@google.com    static Event *
8412955Sgabeblack@google.com    getFromScEvent(sc_core::sc_event *e)
8512955Sgabeblack@google.com    {
8612955Sgabeblack@google.com        return e->_gem5_event;
8712955Sgabeblack@google.com    }
8812955Sgabeblack@google.com
8912955Sgabeblack@google.com    static const Event *
9012955Sgabeblack@google.com    getFromScEvent(const sc_core::sc_event *e)
9112955Sgabeblack@google.com    {
9212955Sgabeblack@google.com        return e->_gem5_event;
9312955Sgabeblack@google.com    }
9412955Sgabeblack@google.com
9512957Sgabeblack@google.com    void addSensitivity(Sensitivity *s) const { sensitivities.insert(s); }
9612957Sgabeblack@google.com    void delSensitivity(Sensitivity *s) const { sensitivities.erase(s); }
9712957Sgabeblack@google.com
9812955Sgabeblack@google.com  private:
9912955Sgabeblack@google.com    sc_core::sc_event *_sc_event;
10012955Sgabeblack@google.com
10112955Sgabeblack@google.com    std::string _basename;
10212955Sgabeblack@google.com    std::string _name;
10312955Sgabeblack@google.com    bool _inHierarchy;
10412955Sgabeblack@google.com
10512955Sgabeblack@google.com    sc_core::sc_object *parent;
10612955Sgabeblack@google.com    EventsIt parentIt;
10712957Sgabeblack@google.com
10812957Sgabeblack@google.com    EventWrapper<Event, &Event::notify> delayedNotify;
10912957Sgabeblack@google.com
11012957Sgabeblack@google.com    mutable std::set<Sensitivity *> sensitivities;
11112955Sgabeblack@google.com};
11212955Sgabeblack@google.com
11312955Sgabeblack@google.comextern Events topLevelEvents;
11412955Sgabeblack@google.comextern Events allEvents;
11512955Sgabeblack@google.com
11612955Sgabeblack@google.comEventsIt findEvent(const std::string &name);
11712955Sgabeblack@google.com
11812955Sgabeblack@google.com} // namespace sc_gem5
11912955Sgabeblack@google.com
12012955Sgabeblack@google.com#endif  //__SYSTEMC_CORE_EVENT_HH__
121