gem5  v21.1.0.2
list.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __SYSTEMC_CORE_LIST_HH__
29 #define __SYSTEMC_CORE_LIST_HH__
30 
31 #include <functional>
32 
33 #include "base/fiber.hh"
34 #include "systemc/core/object.hh"
38 
39 namespace sc_gem5
40 {
41 
42 struct ListNode
43 {
44  ListNode() : nextListNode(nullptr), prevListNode(nullptr) {}
45  virtual ~ListNode() {}
46 
49 
50  void
52  {
53  if (nextListNode)
55  if (prevListNode)
57  nextListNode = nullptr;
58  prevListNode = nullptr;
59  }
60 };
61 
62 template <typename T>
63 struct NodeList : public ListNode
64 {
66  {
67  nextListNode = this;
68  prevListNode = this;
69  }
70 
71  void
73  {
74  // Make sure this node isn't currently in a different list.
75  t->popListNode();
76 
77  // The node behind t is whoever used to be first.
78  t->nextListNode = nextListNode;
79  // The node that used to be first is behind t.
81 
82  // Nobody is in front of t.
83  t->prevListNode = this;
84  // The first node is t.
85  nextListNode = t;
86  }
87 
88  void
89  pushLast(T *t)
90  {
91  // Make sure this node isn't currently in a different list.
92  t->popListNode();
93 
94  // The node in front of t is whoever used to be last.
95  t->prevListNode = prevListNode;
96  // The node that used to be last is in front of t.
98 
99  // Nobody is behind t.
100  t->nextListNode = this;
101  // The last node is t.
102  prevListNode = t;
103  }
104 
105  T *
107  {
108  return empty() ? nullptr : static_cast<T *>(nextListNode);
109  }
110 
111  bool empty() { return nextListNode == this; }
112 };
113 
114 } // namespace sc_gem5
115 
116 #endif //__SYSTEMC_CORE_LIST_HH__
sc_gem5::ListNode::nextListNode
ListNode * nextListNode
Definition: list.hh:47
sc_gem5::NodeList::NodeList
NodeList()
Definition: list.hh:65
sc_gem5::ListNode
Definition: list.hh:42
sc_gem5::ListNode::prevListNode
ListNode * prevListNode
Definition: list.hh:48
sc_gem5::ListNode::~ListNode
virtual ~ListNode()
Definition: list.hh:45
sc_gem5::NodeList::pushLast
void pushLast(T *t)
Definition: list.hh:89
sc_event.hh
sc_gem5::NodeList::pushFirst
void pushFirst(T *t)
Definition: list.hh:72
sc_gem5::ListNode::ListNode
ListNode()
Definition: list.hh:44
sc_gem5::ListNode::popListNode
void popListNode()
Definition: list.hh:51
sc_gem5::NodeList::empty
bool empty()
Definition: list.hh:111
gem5::ArmISA::t
Bitfield< 5 > t
Definition: misc_types.hh:70
sc_module.hh
sc_gem5::NodeList::getNext
T * getNext()
Definition: list.hh:106
sc_process_handle.hh
object.hh
sc_gem5
Definition: sc_clock.cc:41
sc_gem5::NodeList
Definition: list.hh:63
fiber.hh

Generated on Tue Sep 21 2021 12:25:50 for gem5 by doxygen 1.8.17