sc_event.cc revision 12955
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"
3312837Sgabeblack@google.com
3412837Sgabeblack@google.comnamespace sc_core
3512837Sgabeblack@google.com{
3612837Sgabeblack@google.com
3712955Sgabeblack@google.com
3812955Sgabeblack@google.com/*
3912955Sgabeblack@google.com * sc_event_finder
4012955Sgabeblack@google.com */
4112955Sgabeblack@google.com
4212837Sgabeblack@google.comvoid
4312837Sgabeblack@google.comsc_event_finder::warn_unimpl(const char *func) const
4412837Sgabeblack@google.com{
4512837Sgabeblack@google.com    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
4612837Sgabeblack@google.com}
4712837Sgabeblack@google.com
4812955Sgabeblack@google.com
4912955Sgabeblack@google.com/*
5012955Sgabeblack@google.com * sc_event_and_list
5112955Sgabeblack@google.com */
5212955Sgabeblack@google.com
5312955Sgabeblack@google.comsc_event_and_list::sc_event_and_list() : autoDelete(false), busy(0) {}
5412955Sgabeblack@google.com
5512955Sgabeblack@google.comsc_event_and_list::sc_event_and_list(const sc_event_and_list &eal) :
5612955Sgabeblack@google.com    events(eal.events), autoDelete(false), busy(0)
5712955Sgabeblack@google.com{}
5812955Sgabeblack@google.com
5912955Sgabeblack@google.comsc_event_and_list::sc_event_and_list(const sc_event &e) : sc_event_and_list()
6012837Sgabeblack@google.com{
6112955Sgabeblack@google.com    insert(e);
6212837Sgabeblack@google.com}
6312837Sgabeblack@google.com
6412955Sgabeblack@google.comsc_event_and_list::sc_event_and_list(bool auto_delete) :
6512955Sgabeblack@google.com    autoDelete(auto_delete), busy(0)
6612955Sgabeblack@google.com{}
6712837Sgabeblack@google.com
6812955Sgabeblack@google.comsc_event_and_list::~sc_event_and_list() {}
6912837Sgabeblack@google.com
7012837Sgabeblack@google.comsc_event_and_list &
7112955Sgabeblack@google.comsc_event_and_list::operator = (const sc_event_and_list &eal)
7212837Sgabeblack@google.com{
7312955Sgabeblack@google.com    events = eal.events;
7412837Sgabeblack@google.com    return *this;
7512837Sgabeblack@google.com}
7612837Sgabeblack@google.com
7712837Sgabeblack@google.comint
7812837Sgabeblack@google.comsc_event_and_list::size() const
7912837Sgabeblack@google.com{
8012955Sgabeblack@google.com    return events.size();
8112837Sgabeblack@google.com}
8212837Sgabeblack@google.com
8312837Sgabeblack@google.comvoid
8412955Sgabeblack@google.comsc_event_and_list::swap(sc_event_and_list &eal)
8512837Sgabeblack@google.com{
8612955Sgabeblack@google.com    events.swap(eal.events);
8712837Sgabeblack@google.com}
8812837Sgabeblack@google.com
8912837Sgabeblack@google.comsc_event_and_list &
9012955Sgabeblack@google.comsc_event_and_list::operator &= (const sc_event &e)
9112837Sgabeblack@google.com{
9212955Sgabeblack@google.com    insert(e);
9312837Sgabeblack@google.com    return *this;
9412837Sgabeblack@google.com}
9512837Sgabeblack@google.com
9612837Sgabeblack@google.comsc_event_and_list &
9712955Sgabeblack@google.comsc_event_and_list::operator &= (const sc_event_and_list &eal)
9812837Sgabeblack@google.com{
9912955Sgabeblack@google.com    insert(eal);
10012837Sgabeblack@google.com    return *this;
10112837Sgabeblack@google.com}
10212837Sgabeblack@google.com
10312837Sgabeblack@google.comsc_event_and_expr
10412955Sgabeblack@google.comsc_event_and_list::operator & (const sc_event &e) const
10512837Sgabeblack@google.com{
10612955Sgabeblack@google.com    sc_event_and_expr expr;
10712955Sgabeblack@google.com    expr.insert(*this);
10812955Sgabeblack@google.com    expr.insert(e);
10912955Sgabeblack@google.com    return expr;
11012837Sgabeblack@google.com}
11112837Sgabeblack@google.com
11212837Sgabeblack@google.comsc_event_and_expr
11312955Sgabeblack@google.comsc_event_and_list::operator & (const sc_event_and_list &eal)
11412837Sgabeblack@google.com{
11512955Sgabeblack@google.com    sc_event_and_expr expr;
11612955Sgabeblack@google.com    expr.insert(*this);
11712955Sgabeblack@google.com    expr.insert(eal);
11812955Sgabeblack@google.com    return expr;
11912837Sgabeblack@google.com}
12012837Sgabeblack@google.com
12112955Sgabeblack@google.comvoid
12212955Sgabeblack@google.comsc_event_and_list::insert(sc_event const &e)
12312837Sgabeblack@google.com{
12412955Sgabeblack@google.com    events.insert(&e);
12512837Sgabeblack@google.com}
12612837Sgabeblack@google.com
12712955Sgabeblack@google.comvoid
12812955Sgabeblack@google.comsc_event_and_list::insert(sc_event_and_list const &eal)
12912837Sgabeblack@google.com{
13012955Sgabeblack@google.com    events.insert(eal.events.begin(), eal.events.end());
13112837Sgabeblack@google.com}
13212837Sgabeblack@google.com
13312955Sgabeblack@google.com
13412955Sgabeblack@google.com/*
13512955Sgabeblack@google.com * sc_event_or_list
13612955Sgabeblack@google.com */
13712955Sgabeblack@google.com
13812955Sgabeblack@google.comsc_event_or_list::sc_event_or_list() : autoDelete(false), busy(0) {}
13912955Sgabeblack@google.com
14012955Sgabeblack@google.comsc_event_or_list::sc_event_or_list(const sc_event_or_list &eol) :
14112955Sgabeblack@google.com    events(eol.events), autoDelete(false), busy(0)
14212955Sgabeblack@google.com{}
14312955Sgabeblack@google.com
14412955Sgabeblack@google.comsc_event_or_list::sc_event_or_list(const sc_event &e) : sc_event_or_list()
14512837Sgabeblack@google.com{
14612955Sgabeblack@google.com    insert(e);
14712837Sgabeblack@google.com}
14812837Sgabeblack@google.com
14912955Sgabeblack@google.comsc_event_or_list::sc_event_or_list(bool auto_delete) :
15012955Sgabeblack@google.com    autoDelete(auto_delete), busy(0)
15112955Sgabeblack@google.com{}
15212955Sgabeblack@google.com
15312955Sgabeblack@google.comsc_event_or_list &
15412955Sgabeblack@google.comsc_event_or_list::operator = (const sc_event_or_list &eol)
15512837Sgabeblack@google.com{
15612955Sgabeblack@google.com    events = eol.events;
15712837Sgabeblack@google.com    return *this;
15812837Sgabeblack@google.com}
15912837Sgabeblack@google.com
16012955Sgabeblack@google.comsc_event_or_list::~sc_event_or_list() {}
16112837Sgabeblack@google.com
16212837Sgabeblack@google.comint
16312837Sgabeblack@google.comsc_event_or_list::size() const
16412837Sgabeblack@google.com{
16512955Sgabeblack@google.com    return events.size();
16612837Sgabeblack@google.com}
16712837Sgabeblack@google.com
16812837Sgabeblack@google.comvoid
16912955Sgabeblack@google.comsc_event_or_list::swap(sc_event_or_list &eol)
17012837Sgabeblack@google.com{
17112955Sgabeblack@google.com    events.swap(eol.events);
17212837Sgabeblack@google.com}
17312837Sgabeblack@google.com
17412837Sgabeblack@google.comsc_event_or_list &
17512955Sgabeblack@google.comsc_event_or_list::operator |= (const sc_event &e)
17612837Sgabeblack@google.com{
17712955Sgabeblack@google.com    insert(e);
17812837Sgabeblack@google.com    return *this;
17912837Sgabeblack@google.com}
18012837Sgabeblack@google.com
18112837Sgabeblack@google.comsc_event_or_list &
18212955Sgabeblack@google.comsc_event_or_list::operator |= (const sc_event_or_list &eol)
18312837Sgabeblack@google.com{
18412955Sgabeblack@google.com    insert(eol);
18512837Sgabeblack@google.com    return *this;
18612837Sgabeblack@google.com}
18712837Sgabeblack@google.com
18812837Sgabeblack@google.comsc_event_or_expr
18912955Sgabeblack@google.comsc_event_or_list::operator | (const sc_event &e) const
19012837Sgabeblack@google.com{
19112955Sgabeblack@google.com    sc_event_or_expr expr;
19212955Sgabeblack@google.com    expr.insert(*this);
19312955Sgabeblack@google.com    expr.insert(e);
19412955Sgabeblack@google.com    return expr;
19512837Sgabeblack@google.com}
19612837Sgabeblack@google.com
19712837Sgabeblack@google.comsc_event_or_expr
19812955Sgabeblack@google.comsc_event_or_list::operator | (const sc_event_or_list &eol) const
19912837Sgabeblack@google.com{
20012955Sgabeblack@google.com    sc_event_or_expr expr;
20112955Sgabeblack@google.com    expr.insert(*this);
20212955Sgabeblack@google.com    expr.insert(eol);
20312955Sgabeblack@google.com    return expr;
20412955Sgabeblack@google.com}
20512955Sgabeblack@google.com
20612955Sgabeblack@google.comvoid
20712955Sgabeblack@google.comsc_event_or_list::insert(sc_event const &e)
20812955Sgabeblack@google.com{
20912955Sgabeblack@google.com    events.insert(&e);
21012955Sgabeblack@google.com}
21112955Sgabeblack@google.com
21212955Sgabeblack@google.comvoid
21312955Sgabeblack@google.comsc_event_or_list::insert(sc_event_or_list const &eol)
21412955Sgabeblack@google.com{
21512955Sgabeblack@google.com    events.insert(eol.events.begin(), eol.events.end());
21612955Sgabeblack@google.com}
21712955Sgabeblack@google.com
21812955Sgabeblack@google.com
21912955Sgabeblack@google.com/*
22012955Sgabeblack@google.com * sc_event_and_expr
22112955Sgabeblack@google.com */
22212955Sgabeblack@google.com
22312955Sgabeblack@google.com// Move semantics
22412955Sgabeblack@google.comsc_event_and_expr::sc_event_and_expr(sc_event_and_expr const &e) :
22512955Sgabeblack@google.com    list(e.list)
22612955Sgabeblack@google.com{
22712955Sgabeblack@google.com    e.list = nullptr;
22812837Sgabeblack@google.com}
22912837Sgabeblack@google.com
23012837Sgabeblack@google.comsc_event_and_expr::operator const sc_event_and_list &() const
23112837Sgabeblack@google.com{
23212955Sgabeblack@google.com    sc_event_and_list *temp = list;
23312955Sgabeblack@google.com    list = nullptr;
23412955Sgabeblack@google.com    return *temp;
23512837Sgabeblack@google.com}
23612837Sgabeblack@google.com
23712955Sgabeblack@google.comvoid
23812955Sgabeblack@google.comsc_event_and_expr::insert(sc_event const &e) const
23912955Sgabeblack@google.com{
24012955Sgabeblack@google.com    assert(list);
24112955Sgabeblack@google.com    list->insert(e);
24212955Sgabeblack@google.com}
24312955Sgabeblack@google.com
24412955Sgabeblack@google.comvoid
24512955Sgabeblack@google.comsc_event_and_expr::insert(sc_event_and_list const &eal) const
24612955Sgabeblack@google.com{
24712955Sgabeblack@google.com    assert(list);
24812955Sgabeblack@google.com    list->insert(eal);
24912955Sgabeblack@google.com}
25012955Sgabeblack@google.com
25112955Sgabeblack@google.comsc_event_and_expr::~sc_event_and_expr() { delete list; }
25212955Sgabeblack@google.com
25312955Sgabeblack@google.comsc_event_and_expr::sc_event_and_expr() : list(new sc_event_and_list(true)) {}
25412955Sgabeblack@google.com
25512837Sgabeblack@google.comsc_event_and_expr
25612955Sgabeblack@google.comoperator & (sc_event_and_expr expr, sc_event const &e)
25712837Sgabeblack@google.com{
25812955Sgabeblack@google.com    expr.insert(e);
25912837Sgabeblack@google.com    return expr;
26012837Sgabeblack@google.com}
26112837Sgabeblack@google.com
26212837Sgabeblack@google.comsc_event_and_expr
26312955Sgabeblack@google.comoperator & (sc_event_and_expr expr, sc_event_and_list const &eal)
26412837Sgabeblack@google.com{
26512955Sgabeblack@google.com    expr.insert(eal);
26612837Sgabeblack@google.com    return expr;
26712837Sgabeblack@google.com}
26812837Sgabeblack@google.com
26912955Sgabeblack@google.com
27012955Sgabeblack@google.com/*
27112955Sgabeblack@google.com * sc_event_or_expr
27212955Sgabeblack@google.com */
27312955Sgabeblack@google.com
27412955Sgabeblack@google.com// Move semantics
27512955Sgabeblack@google.comsc_event_or_expr::sc_event_or_expr(sc_event_or_expr const &e) :
27612955Sgabeblack@google.com    list(e.list)
27712955Sgabeblack@google.com{
27812955Sgabeblack@google.com    e.list = nullptr;
27912955Sgabeblack@google.com}
28012955Sgabeblack@google.com
28112837Sgabeblack@google.comsc_event_or_expr::operator const sc_event_or_list &() const
28212837Sgabeblack@google.com{
28312955Sgabeblack@google.com    sc_event_or_list *temp = list;
28412955Sgabeblack@google.com    list = NULL;
28512955Sgabeblack@google.com    return *temp;
28612837Sgabeblack@google.com}
28712837Sgabeblack@google.com
28812955Sgabeblack@google.comvoid
28912955Sgabeblack@google.comsc_event_or_expr::insert(sc_event const &e) const
29012955Sgabeblack@google.com{
29112955Sgabeblack@google.com    assert(list);
29212955Sgabeblack@google.com    list->insert(e);
29312955Sgabeblack@google.com}
29412955Sgabeblack@google.com
29512955Sgabeblack@google.comvoid
29612955Sgabeblack@google.comsc_event_or_expr::insert(sc_event_or_list const &eol) const
29712955Sgabeblack@google.com{
29812955Sgabeblack@google.com    assert(list);
29912955Sgabeblack@google.com    list->insert(eol);
30012955Sgabeblack@google.com}
30112955Sgabeblack@google.com
30212955Sgabeblack@google.comsc_event_or_expr::~sc_event_or_expr() { delete list; }
30312955Sgabeblack@google.com
30412955Sgabeblack@google.comsc_event_or_expr::sc_event_or_expr() : list(new sc_event_or_list(true)) {}
30512955Sgabeblack@google.com
30612837Sgabeblack@google.comsc_event_or_expr
30712955Sgabeblack@google.comoperator | (sc_event_or_expr expr, sc_event const &e)
30812837Sgabeblack@google.com{
30912955Sgabeblack@google.com    expr.insert(e);
31012837Sgabeblack@google.com    return expr;
31112837Sgabeblack@google.com}
31212837Sgabeblack@google.com
31312837Sgabeblack@google.comsc_event_or_expr
31412955Sgabeblack@google.comoperator | (sc_event_or_expr expr, sc_event_or_list const &eol)
31512837Sgabeblack@google.com{
31612955Sgabeblack@google.com    expr.insert(eol);
31712837Sgabeblack@google.com    return expr;
31812837Sgabeblack@google.com}
31912837Sgabeblack@google.com
32012837Sgabeblack@google.com
32112955Sgabeblack@google.com/*
32212955Sgabeblack@google.com * sc_event
32312955Sgabeblack@google.com */
32412837Sgabeblack@google.com
32512955Sgabeblack@google.comsc_event::sc_event() : _gem5_event(new ::sc_gem5::Event(this)) {}
32612837Sgabeblack@google.com
32712955Sgabeblack@google.comsc_event::sc_event(const char *_name) :
32812955Sgabeblack@google.com    _gem5_event(new ::sc_gem5::Event(this, _name))
32912955Sgabeblack@google.com{}
33012837Sgabeblack@google.com
33112955Sgabeblack@google.comsc_event::~sc_event() { delete _gem5_event; }
33212955Sgabeblack@google.com
33312955Sgabeblack@google.comconst char *sc_event::name() const { return _gem5_event->name().c_str(); }
33412837Sgabeblack@google.comconst char *
33512837Sgabeblack@google.comsc_event::basename() const
33612837Sgabeblack@google.com{
33712955Sgabeblack@google.com    return _gem5_event->basename().c_str();
33812837Sgabeblack@google.com}
33912955Sgabeblack@google.combool sc_event::in_hierarchy() const { return _gem5_event->inHierarchy(); }
34012837Sgabeblack@google.com
34112837Sgabeblack@google.comsc_object *
34212837Sgabeblack@google.comsc_event::get_parent_object() const
34312837Sgabeblack@google.com{
34412955Sgabeblack@google.com    return _gem5_event->getParentObject();
34512837Sgabeblack@google.com}
34612837Sgabeblack@google.com
34712955Sgabeblack@google.comvoid sc_event::notify() { _gem5_event->notify(); }
34812955Sgabeblack@google.comvoid sc_event::notify(const sc_time &t) { _gem5_event->notify(t); }
34912955Sgabeblack@google.comvoid sc_event::notify(double d, sc_time_unit u) { _gem5_event->notify(d, u); }
35012955Sgabeblack@google.comvoid sc_event::cancel() { _gem5_event->cancel(); }
35112955Sgabeblack@google.combool sc_event::triggered() const { return _gem5_event->triggered(); }
35212955Sgabeblack@google.comvoid sc_event::notify_delayed() { _gem5_event->notify(SC_ZERO_TIME); }
35312955Sgabeblack@google.comvoid sc_event::notify_delayed(const sc_time &t) { _gem5_event->notify(t); }
35412955Sgabeblack@google.com
35512955Sgabeblack@google.comsc_event_and_expr
35612955Sgabeblack@google.comsc_event::operator & (const sc_event &e) const
35712837Sgabeblack@google.com{
35812955Sgabeblack@google.com    sc_event_and_expr expr;
35912955Sgabeblack@google.com    expr.insert(*this);
36012955Sgabeblack@google.com    expr.insert(e);
36112955Sgabeblack@google.com    return expr;
36212915Sgabeblack@google.com}
36312915Sgabeblack@google.com
36412837Sgabeblack@google.comsc_event_and_expr
36512955Sgabeblack@google.comsc_event::operator & (const sc_event_and_list &eal) const
36612837Sgabeblack@google.com{
36712955Sgabeblack@google.com    sc_event_and_expr expr;
36812955Sgabeblack@google.com    expr.insert(*this);
36912955Sgabeblack@google.com    expr.insert(eal);
37012955Sgabeblack@google.com    return expr;
37112837Sgabeblack@google.com}
37212837Sgabeblack@google.com
37312837Sgabeblack@google.comsc_event_or_expr
37412955Sgabeblack@google.comsc_event::operator | (const sc_event &e) const
37512837Sgabeblack@google.com{
37612955Sgabeblack@google.com    sc_event_or_expr expr;
37712955Sgabeblack@google.com    expr.insert(*this);
37812955Sgabeblack@google.com    expr.insert(e);
37912955Sgabeblack@google.com    return expr;
38012837Sgabeblack@google.com}
38112837Sgabeblack@google.com
38212837Sgabeblack@google.comsc_event_or_expr
38312955Sgabeblack@google.comsc_event::operator | (const sc_event_or_list &eol) const
38412837Sgabeblack@google.com{
38512955Sgabeblack@google.com    sc_event_or_expr expr;
38612955Sgabeblack@google.com    expr.insert(*this);
38712955Sgabeblack@google.com    expr.insert(eol);
38812955Sgabeblack@google.com    return expr;
38912837Sgabeblack@google.com}
39012837Sgabeblack@google.com
39112837Sgabeblack@google.comconst std::vector<sc_event *> &
39212837Sgabeblack@google.comsc_get_top_level_events()
39312837Sgabeblack@google.com{
39412955Sgabeblack@google.com    return ::sc_gem5::topLevelEvents;
39512837Sgabeblack@google.com}
39612837Sgabeblack@google.com
39712837Sgabeblack@google.comsc_event *
39812955Sgabeblack@google.comsc_find_event(const char *name)
39912837Sgabeblack@google.com{
40012955Sgabeblack@google.com    std::string str(name);
40112955Sgabeblack@google.com    ::sc_gem5::EventsIt it = ::sc_gem5::findEvent(str);
40212955Sgabeblack@google.com    return it == ::sc_gem5::allEvents.end() ? nullptr : *it;
40312837Sgabeblack@google.com}
40412837Sgabeblack@google.com
40512837Sgabeblack@google.com} // namespace sc_core
406