event.hh revision 13243
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
3313193Sgabeblack@google.com#include <list>
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"
4013206Sgabeblack@google.com#include "systemc/core/process.hh"
4113063Sgabeblack@google.com#include "systemc/core/sched_event.hh"
4213206Sgabeblack@google.com#include "systemc/core/sensitivity.hh"
4312955Sgabeblack@google.com#include "systemc/ext/core/sc_prim.hh"
4412955Sgabeblack@google.com#include "systemc/ext/core/sc_time.hh"
4512955Sgabeblack@google.com
4612955Sgabeblack@google.comnamespace sc_core
4712955Sgabeblack@google.com{
4812955Sgabeblack@google.com
4912955Sgabeblack@google.comclass sc_event;
5012955Sgabeblack@google.com
5112955Sgabeblack@google.com} // namespace sc_core
5212955Sgabeblack@google.com
5312955Sgabeblack@google.comnamespace sc_gem5
5412955Sgabeblack@google.com{
5512955Sgabeblack@google.com
5612955Sgabeblack@google.comtypedef std::vector<sc_core::sc_event *> Events;
5712955Sgabeblack@google.com
5812957Sgabeblack@google.comclass Sensitivity;
5912957Sgabeblack@google.com
6012955Sgabeblack@google.comclass Event
6112955Sgabeblack@google.com{
6212955Sgabeblack@google.com  public:
6312955Sgabeblack@google.com    Event(sc_core::sc_event *_sc_event);
6412955Sgabeblack@google.com    Event(sc_core::sc_event *_sc_event, const char *_basename);
6512955Sgabeblack@google.com
6612955Sgabeblack@google.com    ~Event();
6712955Sgabeblack@google.com
6812955Sgabeblack@google.com    sc_core::sc_event *sc_event() { return _sc_event; }
6912955Sgabeblack@google.com
7012955Sgabeblack@google.com    const std::string &name() const;
7112955Sgabeblack@google.com    const std::string &basename() const;
7212955Sgabeblack@google.com    bool inHierarchy() const;
7312955Sgabeblack@google.com    sc_core::sc_object *getParentObject() const;
7412955Sgabeblack@google.com
7513208Sgabeblack@google.com    void notify(StaticSensitivities &senses);
7613208Sgabeblack@google.com    void notify(DynamicSensitivities &senses);
7713208Sgabeblack@google.com
7812955Sgabeblack@google.com    void notify();
7912955Sgabeblack@google.com    void notify(const sc_core::sc_time &t);
8012955Sgabeblack@google.com    void
8112955Sgabeblack@google.com    notify(double d, sc_core::sc_time_unit &u)
8212955Sgabeblack@google.com    {
8312955Sgabeblack@google.com        notify(sc_core::sc_time(d, u));
8412955Sgabeblack@google.com    }
8512955Sgabeblack@google.com    void cancel();
8612955Sgabeblack@google.com
8712955Sgabeblack@google.com    bool triggered() const;
8813243Sgabeblack@google.com    uint64_t triggeredStamp() const { return _triggeredStamp; }
8912955Sgabeblack@google.com
9012955Sgabeblack@google.com    static Event *
9112955Sgabeblack@google.com    getFromScEvent(sc_core::sc_event *e)
9212955Sgabeblack@google.com    {
9312955Sgabeblack@google.com        return e->_gem5_event;
9412955Sgabeblack@google.com    }
9512955Sgabeblack@google.com
9612955Sgabeblack@google.com    static const Event *
9712955Sgabeblack@google.com    getFromScEvent(const sc_core::sc_event *e)
9812955Sgabeblack@google.com    {
9912955Sgabeblack@google.com        return e->_gem5_event;
10012955Sgabeblack@google.com    }
10112955Sgabeblack@google.com
10213206Sgabeblack@google.com    void
10313206Sgabeblack@google.com    addSensitivity(StaticSensitivity *s) const
10413206Sgabeblack@google.com    {
10513206Sgabeblack@google.com        // Insert static sensitivities in reverse order to match Accellera's
10613206Sgabeblack@google.com        // implementation.
10713208Sgabeblack@google.com        auto &senses = s->ofMethod() ? staticSenseMethod : staticSenseThread;
10813208Sgabeblack@google.com        senses.insert(senses.begin(), s);
10913206Sgabeblack@google.com    }
11013206Sgabeblack@google.com    void
11113206Sgabeblack@google.com    delSensitivity(StaticSensitivity *s) const
11213206Sgabeblack@google.com    {
11313208Sgabeblack@google.com        auto &senses = s->ofMethod() ? staticSenseMethod : staticSenseThread;
11413208Sgabeblack@google.com        for (auto &t: senses) {
11513206Sgabeblack@google.com            if (t == s) {
11613208Sgabeblack@google.com                t = senses.back();
11713208Sgabeblack@google.com                senses.pop_back();
11813206Sgabeblack@google.com                break;
11913206Sgabeblack@google.com            }
12013206Sgabeblack@google.com        }
12113206Sgabeblack@google.com    }
12213206Sgabeblack@google.com    void
12313206Sgabeblack@google.com    addSensitivity(DynamicSensitivity *s) const
12413206Sgabeblack@google.com    {
12513208Sgabeblack@google.com        auto &senses = s->ofMethod() ? dynamicSenseMethod : dynamicSenseThread;
12613208Sgabeblack@google.com        senses.push_back(s);
12713206Sgabeblack@google.com    }
12813206Sgabeblack@google.com    void
12913206Sgabeblack@google.com    delSensitivity(DynamicSensitivity *s) const
13013206Sgabeblack@google.com    {
13113208Sgabeblack@google.com        auto &senses = s->ofMethod() ? dynamicSenseMethod : dynamicSenseThread;
13213208Sgabeblack@google.com        for (auto &t: senses) {
13313206Sgabeblack@google.com            if (t == s) {
13413208Sgabeblack@google.com                t = senses.back();
13513208Sgabeblack@google.com                senses.pop_back();
13613206Sgabeblack@google.com                break;
13713206Sgabeblack@google.com            }
13813206Sgabeblack@google.com        }
13913206Sgabeblack@google.com    }
14012957Sgabeblack@google.com
14112955Sgabeblack@google.com  private:
14212955Sgabeblack@google.com    sc_core::sc_event *_sc_event;
14312955Sgabeblack@google.com
14412955Sgabeblack@google.com    std::string _basename;
14512955Sgabeblack@google.com    std::string _name;
14612955Sgabeblack@google.com    bool _inHierarchy;
14712955Sgabeblack@google.com
14812955Sgabeblack@google.com    sc_core::sc_object *parent;
14912957Sgabeblack@google.com
15013063Sgabeblack@google.com    ScEvent delayedNotify;
15113243Sgabeblack@google.com    mutable uint64_t _triggeredStamp;
15212957Sgabeblack@google.com
15313208Sgabeblack@google.com    mutable StaticSensitivities staticSenseMethod;
15413208Sgabeblack@google.com    mutable StaticSensitivities staticSenseThread;
15513208Sgabeblack@google.com    mutable DynamicSensitivities dynamicSenseMethod;
15613208Sgabeblack@google.com    mutable DynamicSensitivities dynamicSenseThread;
15712955Sgabeblack@google.com};
15812955Sgabeblack@google.com
15912955Sgabeblack@google.comextern Events topLevelEvents;
16012955Sgabeblack@google.comextern Events allEvents;
16112955Sgabeblack@google.com
16212955Sgabeblack@google.comEventsIt findEvent(const std::string &name);
16312955Sgabeblack@google.com
16412955Sgabeblack@google.com} // namespace sc_gem5
16512955Sgabeblack@google.com
16612955Sgabeblack@google.com#endif  //__SYSTEMC_CORE_EVENT_HH__
167