sc_event.cc revision 13279
112837Sgabeblack@google.com/*
212837Sgabeblack@google.com * Copyright 2018 Google, Inc.
312837Sgabeblack@google.com *
412837Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512837Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612837Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812837Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012837Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112837Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212837Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312837Sgabeblack@google.com * this software without specific prior written permission.
1412837Sgabeblack@google.com *
1512837Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612837Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712837Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812837Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912837Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012837Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112837Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212837Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312837Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412837Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512837Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612837Sgabeblack@google.com *
2712837Sgabeblack@google.com * Authors: Gabe Black
2812837Sgabeblack@google.com */
2912837Sgabeblack@google.com
3012837Sgabeblack@google.com#include "base/logging.hh"
3112955Sgabeblack@google.com#include "systemc/core/event.hh"
3212837Sgabeblack@google.com#include "systemc/ext/core/sc_event.hh"
3313279Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh"
3412837Sgabeblack@google.com
3512837Sgabeblack@google.comnamespace sc_core
3612837Sgabeblack@google.com{
3712837Sgabeblack@google.com
3812955Sgabeblack@google.com
3912955Sgabeblack@google.com/*
4012955Sgabeblack@google.com * sc_event_and_list
4112955Sgabeblack@google.com */
4212955Sgabeblack@google.com
4312955Sgabeblack@google.comsc_event_and_list::sc_event_and_list() : autoDelete(false), busy(0) {}
4412955Sgabeblack@google.com
4512955Sgabeblack@google.comsc_event_and_list::sc_event_and_list(const sc_event_and_list &eal) :
4612955Sgabeblack@google.com    events(eal.events), autoDelete(false), busy(0)
4712955Sgabeblack@google.com{}
4812955Sgabeblack@google.com
4912955Sgabeblack@google.comsc_event_and_list::sc_event_and_list(const sc_event &e) : sc_event_and_list()
5012837Sgabeblack@google.com{
5112955Sgabeblack@google.com    insert(e);
5212837Sgabeblack@google.com}
5312837Sgabeblack@google.com
5412955Sgabeblack@google.comsc_event_and_list::sc_event_and_list(bool auto_delete) :
5512955Sgabeblack@google.com    autoDelete(auto_delete), busy(0)
5612955Sgabeblack@google.com{}
5712837Sgabeblack@google.com
5812955Sgabeblack@google.comsc_event_and_list::~sc_event_and_list() {}
5912837Sgabeblack@google.com
6012837Sgabeblack@google.comsc_event_and_list &
6112955Sgabeblack@google.comsc_event_and_list::operator = (const sc_event_and_list &eal)
6212837Sgabeblack@google.com{
6312955Sgabeblack@google.com    events = eal.events;
6412837Sgabeblack@google.com    return *this;
6512837Sgabeblack@google.com}
6612837Sgabeblack@google.com
6712837Sgabeblack@google.comint
6812837Sgabeblack@google.comsc_event_and_list::size() const
6912837Sgabeblack@google.com{
7012955Sgabeblack@google.com    return events.size();
7112837Sgabeblack@google.com}
7212837Sgabeblack@google.com
7312837Sgabeblack@google.comvoid
7412955Sgabeblack@google.comsc_event_and_list::swap(sc_event_and_list &eal)
7512837Sgabeblack@google.com{
7612955Sgabeblack@google.com    events.swap(eal.events);
7712837Sgabeblack@google.com}
7812837Sgabeblack@google.com
7912837Sgabeblack@google.comsc_event_and_list &
8012955Sgabeblack@google.comsc_event_and_list::operator &= (const sc_event &e)
8112837Sgabeblack@google.com{
8212955Sgabeblack@google.com    insert(e);
8312837Sgabeblack@google.com    return *this;
8412837Sgabeblack@google.com}
8512837Sgabeblack@google.com
8612837Sgabeblack@google.comsc_event_and_list &
8712955Sgabeblack@google.comsc_event_and_list::operator &= (const sc_event_and_list &eal)
8812837Sgabeblack@google.com{
8912955Sgabeblack@google.com    insert(eal);
9012837Sgabeblack@google.com    return *this;
9112837Sgabeblack@google.com}
9212837Sgabeblack@google.com
9312837Sgabeblack@google.comsc_event_and_expr
9412955Sgabeblack@google.comsc_event_and_list::operator & (const sc_event &e) const
9512837Sgabeblack@google.com{
9612955Sgabeblack@google.com    sc_event_and_expr expr;
9712955Sgabeblack@google.com    expr.insert(*this);
9812955Sgabeblack@google.com    expr.insert(e);
9912955Sgabeblack@google.com    return expr;
10012837Sgabeblack@google.com}
10112837Sgabeblack@google.com
10212837Sgabeblack@google.comsc_event_and_expr
10312955Sgabeblack@google.comsc_event_and_list::operator & (const sc_event_and_list &eal)
10412837Sgabeblack@google.com{
10512955Sgabeblack@google.com    sc_event_and_expr expr;
10612955Sgabeblack@google.com    expr.insert(*this);
10712955Sgabeblack@google.com    expr.insert(eal);
10812955Sgabeblack@google.com    return expr;
10912837Sgabeblack@google.com}
11012837Sgabeblack@google.com
11112955Sgabeblack@google.comvoid
11212955Sgabeblack@google.comsc_event_and_list::insert(sc_event const &e)
11312837Sgabeblack@google.com{
11412955Sgabeblack@google.com    events.insert(&e);
11512837Sgabeblack@google.com}
11612837Sgabeblack@google.com
11712955Sgabeblack@google.comvoid
11812955Sgabeblack@google.comsc_event_and_list::insert(sc_event_and_list const &eal)
11912837Sgabeblack@google.com{
12012955Sgabeblack@google.com    events.insert(eal.events.begin(), eal.events.end());
12112837Sgabeblack@google.com}
12212837Sgabeblack@google.com
12312955Sgabeblack@google.com
12412955Sgabeblack@google.com/*
12512955Sgabeblack@google.com * sc_event_or_list
12612955Sgabeblack@google.com */
12712955Sgabeblack@google.com
12812955Sgabeblack@google.comsc_event_or_list::sc_event_or_list() : autoDelete(false), busy(0) {}
12912955Sgabeblack@google.com
13012955Sgabeblack@google.comsc_event_or_list::sc_event_or_list(const sc_event_or_list &eol) :
13112955Sgabeblack@google.com    events(eol.events), autoDelete(false), busy(0)
13212955Sgabeblack@google.com{}
13312955Sgabeblack@google.com
13412955Sgabeblack@google.comsc_event_or_list::sc_event_or_list(const sc_event &e) : sc_event_or_list()
13512837Sgabeblack@google.com{
13612955Sgabeblack@google.com    insert(e);
13712837Sgabeblack@google.com}
13812837Sgabeblack@google.com
13912955Sgabeblack@google.comsc_event_or_list::sc_event_or_list(bool auto_delete) :
14012955Sgabeblack@google.com    autoDelete(auto_delete), busy(0)
14112955Sgabeblack@google.com{}
14212955Sgabeblack@google.com
14312955Sgabeblack@google.comsc_event_or_list &
14412955Sgabeblack@google.comsc_event_or_list::operator = (const sc_event_or_list &eol)
14512837Sgabeblack@google.com{
14612955Sgabeblack@google.com    events = eol.events;
14712837Sgabeblack@google.com    return *this;
14812837Sgabeblack@google.com}
14912837Sgabeblack@google.com
15012955Sgabeblack@google.comsc_event_or_list::~sc_event_or_list() {}
15112837Sgabeblack@google.com
15212837Sgabeblack@google.comint
15312837Sgabeblack@google.comsc_event_or_list::size() const
15412837Sgabeblack@google.com{
15512955Sgabeblack@google.com    return events.size();
15612837Sgabeblack@google.com}
15712837Sgabeblack@google.com
15812837Sgabeblack@google.comvoid
15912955Sgabeblack@google.comsc_event_or_list::swap(sc_event_or_list &eol)
16012837Sgabeblack@google.com{
16112955Sgabeblack@google.com    events.swap(eol.events);
16212837Sgabeblack@google.com}
16312837Sgabeblack@google.com
16412837Sgabeblack@google.comsc_event_or_list &
16512955Sgabeblack@google.comsc_event_or_list::operator |= (const sc_event &e)
16612837Sgabeblack@google.com{
16712955Sgabeblack@google.com    insert(e);
16812837Sgabeblack@google.com    return *this;
16912837Sgabeblack@google.com}
17012837Sgabeblack@google.com
17112837Sgabeblack@google.comsc_event_or_list &
17212955Sgabeblack@google.comsc_event_or_list::operator |= (const sc_event_or_list &eol)
17312837Sgabeblack@google.com{
17412955Sgabeblack@google.com    insert(eol);
17512837Sgabeblack@google.com    return *this;
17612837Sgabeblack@google.com}
17712837Sgabeblack@google.com
17812837Sgabeblack@google.comsc_event_or_expr
17912955Sgabeblack@google.comsc_event_or_list::operator | (const sc_event &e) const
18012837Sgabeblack@google.com{
18112955Sgabeblack@google.com    sc_event_or_expr expr;
18212955Sgabeblack@google.com    expr.insert(*this);
18312955Sgabeblack@google.com    expr.insert(e);
18412955Sgabeblack@google.com    return expr;
18512837Sgabeblack@google.com}
18612837Sgabeblack@google.com
18712837Sgabeblack@google.comsc_event_or_expr
18812955Sgabeblack@google.comsc_event_or_list::operator | (const sc_event_or_list &eol) const
18912837Sgabeblack@google.com{
19012955Sgabeblack@google.com    sc_event_or_expr expr;
19112955Sgabeblack@google.com    expr.insert(*this);
19212955Sgabeblack@google.com    expr.insert(eol);
19312955Sgabeblack@google.com    return expr;
19412955Sgabeblack@google.com}
19512955Sgabeblack@google.com
19612955Sgabeblack@google.comvoid
19712955Sgabeblack@google.comsc_event_or_list::insert(sc_event const &e)
19812955Sgabeblack@google.com{
19912955Sgabeblack@google.com    events.insert(&e);
20012955Sgabeblack@google.com}
20112955Sgabeblack@google.com
20212955Sgabeblack@google.comvoid
20312955Sgabeblack@google.comsc_event_or_list::insert(sc_event_or_list const &eol)
20412955Sgabeblack@google.com{
20512955Sgabeblack@google.com    events.insert(eol.events.begin(), eol.events.end());
20612955Sgabeblack@google.com}
20712955Sgabeblack@google.com
20812955Sgabeblack@google.com
20912955Sgabeblack@google.com/*
21012955Sgabeblack@google.com * sc_event_and_expr
21112955Sgabeblack@google.com */
21212955Sgabeblack@google.com
21312955Sgabeblack@google.com// Move semantics
21412955Sgabeblack@google.comsc_event_and_expr::sc_event_and_expr(sc_event_and_expr const &e) :
21512955Sgabeblack@google.com    list(e.list)
21612955Sgabeblack@google.com{
21712955Sgabeblack@google.com    e.list = nullptr;
21812837Sgabeblack@google.com}
21912837Sgabeblack@google.com
22012837Sgabeblack@google.comsc_event_and_expr::operator const sc_event_and_list &() const
22112837Sgabeblack@google.com{
22212955Sgabeblack@google.com    sc_event_and_list *temp = list;
22312955Sgabeblack@google.com    list = nullptr;
22412955Sgabeblack@google.com    return *temp;
22512837Sgabeblack@google.com}
22612837Sgabeblack@google.com
22712955Sgabeblack@google.comvoid
22812955Sgabeblack@google.comsc_event_and_expr::insert(sc_event const &e) const
22912955Sgabeblack@google.com{
23012955Sgabeblack@google.com    assert(list);
23112955Sgabeblack@google.com    list->insert(e);
23212955Sgabeblack@google.com}
23312955Sgabeblack@google.com
23412955Sgabeblack@google.comvoid
23512955Sgabeblack@google.comsc_event_and_expr::insert(sc_event_and_list const &eal) const
23612955Sgabeblack@google.com{
23712955Sgabeblack@google.com    assert(list);
23812955Sgabeblack@google.com    list->insert(eal);
23912955Sgabeblack@google.com}
24012955Sgabeblack@google.com
24112955Sgabeblack@google.comsc_event_and_expr::~sc_event_and_expr() { delete list; }
24212955Sgabeblack@google.com
24312955Sgabeblack@google.comsc_event_and_expr::sc_event_and_expr() : list(new sc_event_and_list(true)) {}
24412955Sgabeblack@google.com
24512837Sgabeblack@google.comsc_event_and_expr
24612955Sgabeblack@google.comoperator & (sc_event_and_expr expr, sc_event const &e)
24712837Sgabeblack@google.com{
24812955Sgabeblack@google.com    expr.insert(e);
24912837Sgabeblack@google.com    return expr;
25012837Sgabeblack@google.com}
25112837Sgabeblack@google.com
25212837Sgabeblack@google.comsc_event_and_expr
25312955Sgabeblack@google.comoperator & (sc_event_and_expr expr, sc_event_and_list const &eal)
25412837Sgabeblack@google.com{
25512955Sgabeblack@google.com    expr.insert(eal);
25612837Sgabeblack@google.com    return expr;
25712837Sgabeblack@google.com}
25812837Sgabeblack@google.com
25912955Sgabeblack@google.com
26012955Sgabeblack@google.com/*
26112955Sgabeblack@google.com * sc_event_or_expr
26212955Sgabeblack@google.com */
26312955Sgabeblack@google.com
26412955Sgabeblack@google.com// Move semantics
26512955Sgabeblack@google.comsc_event_or_expr::sc_event_or_expr(sc_event_or_expr const &e) :
26612955Sgabeblack@google.com    list(e.list)
26712955Sgabeblack@google.com{
26812955Sgabeblack@google.com    e.list = nullptr;
26912955Sgabeblack@google.com}
27012955Sgabeblack@google.com
27112837Sgabeblack@google.comsc_event_or_expr::operator const sc_event_or_list &() const
27212837Sgabeblack@google.com{
27312955Sgabeblack@google.com    sc_event_or_list *temp = list;
27412955Sgabeblack@google.com    list = NULL;
27512955Sgabeblack@google.com    return *temp;
27612837Sgabeblack@google.com}
27712837Sgabeblack@google.com
27812955Sgabeblack@google.comvoid
27912955Sgabeblack@google.comsc_event_or_expr::insert(sc_event const &e) const
28012955Sgabeblack@google.com{
28112955Sgabeblack@google.com    assert(list);
28212955Sgabeblack@google.com    list->insert(e);
28312955Sgabeblack@google.com}
28412955Sgabeblack@google.com
28512955Sgabeblack@google.comvoid
28612955Sgabeblack@google.comsc_event_or_expr::insert(sc_event_or_list const &eol) const
28712955Sgabeblack@google.com{
28812955Sgabeblack@google.com    assert(list);
28912955Sgabeblack@google.com    list->insert(eol);
29012955Sgabeblack@google.com}
29112955Sgabeblack@google.com
29212955Sgabeblack@google.comsc_event_or_expr::~sc_event_or_expr() { delete list; }
29312955Sgabeblack@google.com
29412955Sgabeblack@google.comsc_event_or_expr::sc_event_or_expr() : list(new sc_event_or_list(true)) {}
29512955Sgabeblack@google.com
29612837Sgabeblack@google.comsc_event_or_expr
29712955Sgabeblack@google.comoperator | (sc_event_or_expr expr, sc_event const &e)
29812837Sgabeblack@google.com{
29912955Sgabeblack@google.com    expr.insert(e);
30012837Sgabeblack@google.com    return expr;
30112837Sgabeblack@google.com}
30212837Sgabeblack@google.com
30312837Sgabeblack@google.comsc_event_or_expr
30412955Sgabeblack@google.comoperator | (sc_event_or_expr expr, sc_event_or_list const &eol)
30512837Sgabeblack@google.com{
30612955Sgabeblack@google.com    expr.insert(eol);
30712837Sgabeblack@google.com    return expr;
30812837Sgabeblack@google.com}
30912837Sgabeblack@google.com
31012837Sgabeblack@google.com
31112955Sgabeblack@google.com/*
31212955Sgabeblack@google.com * sc_event
31312955Sgabeblack@google.com */
31412837Sgabeblack@google.com
31513279Sgabeblack@google.comsc_event::sc_event() :
31613279Sgabeblack@google.com    _gem5_event(new ::sc_gem5::Event(
31713279Sgabeblack@google.com                this, sc_core::sc_gen_unique_name("event")))
31813279Sgabeblack@google.com{}
31912837Sgabeblack@google.com
32012955Sgabeblack@google.comsc_event::sc_event(const char *_name) :
32112955Sgabeblack@google.com    _gem5_event(new ::sc_gem5::Event(this, _name))
32212955Sgabeblack@google.com{}
32312837Sgabeblack@google.com
32412955Sgabeblack@google.comsc_event::~sc_event() { delete _gem5_event; }
32512955Sgabeblack@google.com
32612955Sgabeblack@google.comconst char *sc_event::name() const { return _gem5_event->name().c_str(); }
32712837Sgabeblack@google.comconst char *
32812837Sgabeblack@google.comsc_event::basename() const
32912837Sgabeblack@google.com{
33012955Sgabeblack@google.com    return _gem5_event->basename().c_str();
33112837Sgabeblack@google.com}
33212955Sgabeblack@google.combool sc_event::in_hierarchy() const { return _gem5_event->inHierarchy(); }
33312837Sgabeblack@google.com
33412837Sgabeblack@google.comsc_object *
33512837Sgabeblack@google.comsc_event::get_parent_object() const
33612837Sgabeblack@google.com{
33712955Sgabeblack@google.com    return _gem5_event->getParentObject();
33812837Sgabeblack@google.com}
33912837Sgabeblack@google.com
34012955Sgabeblack@google.comvoid sc_event::notify() { _gem5_event->notify(); }
34112955Sgabeblack@google.comvoid sc_event::notify(const sc_time &t) { _gem5_event->notify(t); }
34212955Sgabeblack@google.comvoid sc_event::notify(double d, sc_time_unit u) { _gem5_event->notify(d, u); }
34312955Sgabeblack@google.comvoid sc_event::cancel() { _gem5_event->cancel(); }
34412955Sgabeblack@google.combool sc_event::triggered() const { return _gem5_event->triggered(); }
34512955Sgabeblack@google.comvoid sc_event::notify_delayed() { _gem5_event->notify(SC_ZERO_TIME); }
34612955Sgabeblack@google.comvoid sc_event::notify_delayed(const sc_time &t) { _gem5_event->notify(t); }
34712955Sgabeblack@google.com
34812955Sgabeblack@google.comsc_event_and_expr
34912955Sgabeblack@google.comsc_event::operator & (const sc_event &e) const
35012837Sgabeblack@google.com{
35112955Sgabeblack@google.com    sc_event_and_expr expr;
35212955Sgabeblack@google.com    expr.insert(*this);
35312955Sgabeblack@google.com    expr.insert(e);
35412955Sgabeblack@google.com    return expr;
35512915Sgabeblack@google.com}
35612915Sgabeblack@google.com
35712837Sgabeblack@google.comsc_event_and_expr
35812955Sgabeblack@google.comsc_event::operator & (const sc_event_and_list &eal) const
35912837Sgabeblack@google.com{
36012955Sgabeblack@google.com    sc_event_and_expr expr;
36112955Sgabeblack@google.com    expr.insert(*this);
36212955Sgabeblack@google.com    expr.insert(eal);
36312955Sgabeblack@google.com    return expr;
36412837Sgabeblack@google.com}
36512837Sgabeblack@google.com
36612837Sgabeblack@google.comsc_event_or_expr
36712955Sgabeblack@google.comsc_event::operator | (const sc_event &e) const
36812837Sgabeblack@google.com{
36912955Sgabeblack@google.com    sc_event_or_expr expr;
37012955Sgabeblack@google.com    expr.insert(*this);
37112955Sgabeblack@google.com    expr.insert(e);
37212955Sgabeblack@google.com    return expr;
37312837Sgabeblack@google.com}
37412837Sgabeblack@google.com
37512837Sgabeblack@google.comsc_event_or_expr
37612955Sgabeblack@google.comsc_event::operator | (const sc_event_or_list &eol) const
37712837Sgabeblack@google.com{
37812955Sgabeblack@google.com    sc_event_or_expr expr;
37912955Sgabeblack@google.com    expr.insert(*this);
38012955Sgabeblack@google.com    expr.insert(eol);
38112955Sgabeblack@google.com    return expr;
38212837Sgabeblack@google.com}
38312837Sgabeblack@google.com
38412837Sgabeblack@google.comconst std::vector<sc_event *> &
38512837Sgabeblack@google.comsc_get_top_level_events()
38612837Sgabeblack@google.com{
38712955Sgabeblack@google.com    return ::sc_gem5::topLevelEvents;
38812837Sgabeblack@google.com}
38912837Sgabeblack@google.com
39012837Sgabeblack@google.comsc_event *
39112955Sgabeblack@google.comsc_find_event(const char *name)
39212837Sgabeblack@google.com{
39312955Sgabeblack@google.com    std::string str(name);
39412955Sgabeblack@google.com    ::sc_gem5::EventsIt it = ::sc_gem5::findEvent(str);
39512955Sgabeblack@google.com    return it == ::sc_gem5::allEvents.end() ? nullptr : *it;
39612837Sgabeblack@google.com}
39712837Sgabeblack@google.com
39812837Sgabeblack@google.com} // namespace sc_core
399