event.hh revision 13206:c944ef4abb48
12315SN/A/*
28733Sgeoffrey.blake@arm.com * Copyright 2018 Google, Inc.
39920Syasuko.eckert@amd.com *
48733Sgeoffrey.blake@arm.com * Redistribution and use in source and binary forms, with or without
58733Sgeoffrey.blake@arm.com * modification, are permitted provided that the following conditions are
68733Sgeoffrey.blake@arm.com * met: redistributions of source code must retain the above copyright
78733Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer;
88733Sgeoffrey.blake@arm.com * redistributions in binary form must reproduce the above copyright
98733Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer in the
108733Sgeoffrey.blake@arm.com * documentation and/or other materials provided with the distribution;
118733Sgeoffrey.blake@arm.com * neither the name of the copyright holders nor the names of its
128733Sgeoffrey.blake@arm.com * contributors may be used to endorse or promote products derived from
138733Sgeoffrey.blake@arm.com * this software without specific prior written permission.
148733Sgeoffrey.blake@arm.com *
152332SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162315SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172315SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182315SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
192315SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
202315SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
212315SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
222315SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
232315SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242315SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
252315SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262315SN/A *
272315SN/A * Authors: Gabe Black
282315SN/A */
292315SN/A
302315SN/A#ifndef __SYSTEMC_CORE_EVENT_HH__
312315SN/A#define __SYSTEMC_CORE_EVENT_HH__
322315SN/A
332315SN/A#include <list>
342315SN/A#include <string>
352315SN/A#include <vector>
362315SN/A
372315SN/A#include "sim/eventq.hh"
382315SN/A#include "systemc/core/list.hh"
392315SN/A#include "systemc/core/object.hh"
402689Sktlim@umich.edu#include "systemc/core/process.hh"
412689Sktlim@umich.edu#include "systemc/core/sched_event.hh"
422315SN/A#include "systemc/core/sensitivity.hh"
432315SN/A#include "systemc/ext/core/sc_prim.hh"
442315SN/A#include "systemc/ext/core/sc_time.hh"
452315SN/A
462315SN/Anamespace sc_core
472315SN/A{
488229Snate@binkert.org
492315SN/Aclass sc_event;
502315SN/A
512669Sktlim@umich.edu} // namespace sc_core
522315SN/A
532315SN/Anamespace sc_gem5
542315SN/A{
5510319SAndreas.Sandberg@ARM.com
568229Snate@binkert.orgtypedef std::vector<sc_core::sc_event *> Events;
572683Sktlim@umich.edu
582315SN/Aclass Sensitivity;
598733Sgeoffrey.blake@arm.com
608733Sgeoffrey.blake@arm.comclass Event
612315SN/A{
622315SN/A  public:
632315SN/A    Event(sc_core::sc_event *_sc_event);
643468Sgblack@eecs.umich.edu    Event(sc_core::sc_event *_sc_event, const char *_basename);
653468Sgblack@eecs.umich.edu
666022Sgblack@eecs.umich.edu    ~Event();
673468Sgblack@eecs.umich.edu
682315SN/A    sc_core::sc_event *sc_event() { return _sc_event; }
692315SN/A
702315SN/A    const std::string &name() const;
712680Sktlim@umich.edu    const std::string &basename() const;
722669Sktlim@umich.edu    bool inHierarchy() const;
732315SN/A    sc_core::sc_object *getParentObject() const;
742350SN/A
752350SN/A    void notify();
762350SN/A    void notify(const sc_core::sc_time &t);
772350SN/A    void
782350SN/A    notify(double d, sc_core::sc_time_unit &u)
792350SN/A    {
802350SN/A        notify(sc_core::sc_time(d, u));
812350SN/A    }
822350SN/A    void cancel();
832350SN/A
842680Sktlim@umich.edu    bool triggered() const;
852683Sktlim@umich.edu
862680Sktlim@umich.edu    static Event *
872350SN/A    getFromScEvent(sc_core::sc_event *e)
882680Sktlim@umich.edu    {
892350SN/A        return e->_gem5_event;
9010319SAndreas.Sandberg@ARM.com    }
912315SN/A
922315SN/A    static const Event *
932315SN/A    getFromScEvent(const sc_core::sc_event *e)
942669Sktlim@umich.edu    {
952669Sktlim@umich.edu        return e->_gem5_event;
962315SN/A    }
978832SAli.Saidi@ARM.com
988832SAli.Saidi@ARM.com    void
998832SAli.Saidi@ARM.com    addSensitivity(StaticSensitivity *s) const
1002315SN/A    {
1012315SN/A        // Insert static sensitivities in reverse order to match Accellera's
1022315SN/A        // implementation.
1035529Snate@binkert.org        staticSensitivities.insert(staticSensitivities.begin(), s);
1042315SN/A    }
1052315SN/A    void
1062315SN/A    delSensitivity(StaticSensitivity *s) const
1072315SN/A    {
1082315SN/A        for (auto &t: staticSensitivities) {
1099608Sandreas.hansson@arm.com            if (t == s) {
1102679Sktlim@umich.edu                t = staticSensitivities.back();
1119608Sandreas.hansson@arm.com                staticSensitivities.pop_back();
1122679Sktlim@umich.edu                break;
1139608Sandreas.hansson@arm.com            }
1148887Sgeoffrey.blake@arm.com        }
1159176Sandreas.hansson@arm.com    }
1169176Sandreas.hansson@arm.com    void
1179176Sandreas.hansson@arm.com    addSensitivity(DynamicSensitivity *s) const
1188887Sgeoffrey.blake@arm.com    {
1198887Sgeoffrey.blake@arm.com        dynamicSensitivities.push_back(s);
1208887Sgeoffrey.blake@arm.com    }
1219608Sandreas.hansson@arm.com    void
1228887Sgeoffrey.blake@arm.com    delSensitivity(DynamicSensitivity *s) const
1239176Sandreas.hansson@arm.com    {
1249176Sandreas.hansson@arm.com        for (auto &t: dynamicSensitivities) {
1259176Sandreas.hansson@arm.com            if (t == s) {
1268887Sgeoffrey.blake@arm.com                t = dynamicSensitivities.back();
1278887Sgeoffrey.blake@arm.com                dynamicSensitivities.pop_back();
1282679Sktlim@umich.edu                break;
1299176Sandreas.hansson@arm.com            }
1309176Sandreas.hansson@arm.com        }
1319176Sandreas.hansson@arm.com    }
1329176Sandreas.hansson@arm.com
1339176Sandreas.hansson@arm.com  private:
1349176Sandreas.hansson@arm.com    sc_core::sc_event *_sc_event;
1359608Sandreas.hansson@arm.com
1369608Sandreas.hansson@arm.com    std::string _basename;
1372315SN/A    std::string _name;
1382680Sktlim@umich.edu    bool _inHierarchy;
1392315SN/A
1406022Sgblack@eecs.umich.edu    sc_core::sc_object *parent;
1416022Sgblack@eecs.umich.edu
1422315SN/A    ScEvent delayedNotify;
1432315SN/A
1442315SN/A    mutable StaticSensitivities staticSensitivities;
1452315SN/A    mutable DynamicSensitivities dynamicSensitivities;
1462315SN/A};
1472315SN/A
1488733Sgeoffrey.blake@arm.comextern Events topLevelEvents;
1498733Sgeoffrey.blake@arm.comextern Events allEvents;
1508733Sgeoffrey.blake@arm.com
1518733Sgeoffrey.blake@arm.comEventsIt findEvent(const std::string &name);
1522315SN/A
1532315SN/A} // namespace sc_gem5
1548733Sgeoffrey.blake@arm.com
1558733Sgeoffrey.blake@arm.com#endif  //__SYSTEMC_CORE_EVENT_HH__
1568733Sgeoffrey.blake@arm.com