112953Sgabeblack@google.com/* 212953Sgabeblack@google.com * Copyright 2018 Google, Inc. 312953Sgabeblack@google.com * 412953Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512953Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612953Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712953Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812953Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912953Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012953Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112953Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212953Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312953Sgabeblack@google.com * this software without specific prior written permission. 1412953Sgabeblack@google.com * 1512953Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612953Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712953Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812953Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912953Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012953Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112953Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212953Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312953Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412953Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512953Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612953Sgabeblack@google.com * 2712953Sgabeblack@google.com * Authors: Gabe Black 2812953Sgabeblack@google.com */ 2912953Sgabeblack@google.com 3012953Sgabeblack@google.com#ifndef __SYSTEMC_CORE_LIST_HH__ 3112953Sgabeblack@google.com#define __SYSTEMC_CORE_LIST_HH__ 3212953Sgabeblack@google.com 3312953Sgabeblack@google.com#include <functional> 3412953Sgabeblack@google.com 3512953Sgabeblack@google.com#include "base/fiber.hh" 3612953Sgabeblack@google.com#include "systemc/core/object.hh" 3712953Sgabeblack@google.com#include "systemc/ext/core/sc_event.hh" 3812953Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh" 3912953Sgabeblack@google.com#include "systemc/ext/core/sc_process_handle.hh" 4012953Sgabeblack@google.com 4112953Sgabeblack@google.comnamespace sc_gem5 4212953Sgabeblack@google.com{ 4312953Sgabeblack@google.com 4412953Sgabeblack@google.comstruct ListNode 4512953Sgabeblack@google.com{ 4612953Sgabeblack@google.com ListNode() : nextListNode(nullptr), prevListNode(nullptr) {} 4712953Sgabeblack@google.com virtual ~ListNode() {} 4812953Sgabeblack@google.com 4912953Sgabeblack@google.com ListNode *nextListNode; 5012953Sgabeblack@google.com ListNode *prevListNode; 5112953Sgabeblack@google.com 5212953Sgabeblack@google.com void 5312953Sgabeblack@google.com popListNode() 5412953Sgabeblack@google.com { 5512953Sgabeblack@google.com if (nextListNode) 5612953Sgabeblack@google.com nextListNode->prevListNode = prevListNode; 5712953Sgabeblack@google.com if (prevListNode) 5812953Sgabeblack@google.com prevListNode->nextListNode = nextListNode; 5912953Sgabeblack@google.com nextListNode = nullptr; 6012953Sgabeblack@google.com prevListNode = nullptr; 6112953Sgabeblack@google.com } 6212953Sgabeblack@google.com}; 6312953Sgabeblack@google.com 6412953Sgabeblack@google.comtemplate <typename T> 6512953Sgabeblack@google.comstruct NodeList : public ListNode 6612953Sgabeblack@google.com{ 6712953Sgabeblack@google.com NodeList() 6812953Sgabeblack@google.com { 6912953Sgabeblack@google.com nextListNode = this; 7012953Sgabeblack@google.com prevListNode = this; 7112953Sgabeblack@google.com } 7212953Sgabeblack@google.com 7312953Sgabeblack@google.com void 7412953Sgabeblack@google.com pushFirst(T *t) 7512953Sgabeblack@google.com { 7612953Sgabeblack@google.com // Make sure this node isn't currently in a different list. 7712953Sgabeblack@google.com t->popListNode(); 7812953Sgabeblack@google.com 7912953Sgabeblack@google.com // The node behind t is whoever used to be first. 8012953Sgabeblack@google.com t->nextListNode = nextListNode; 8112953Sgabeblack@google.com // The node that used to be first is behind t. 8212953Sgabeblack@google.com nextListNode->prevListNode = t; 8312953Sgabeblack@google.com 8412953Sgabeblack@google.com // Nobody is in front of t. 8512953Sgabeblack@google.com t->prevListNode = this; 8612953Sgabeblack@google.com // The first node is t. 8712953Sgabeblack@google.com nextListNode = t; 8812953Sgabeblack@google.com } 8912953Sgabeblack@google.com 9012953Sgabeblack@google.com void 9112953Sgabeblack@google.com pushLast(T *t) 9212953Sgabeblack@google.com { 9312953Sgabeblack@google.com // Make sure this node isn't currently in a different list. 9412953Sgabeblack@google.com t->popListNode(); 9512953Sgabeblack@google.com 9612953Sgabeblack@google.com // The node in front of t is whoever used to be last. 9712953Sgabeblack@google.com t->prevListNode = prevListNode; 9812953Sgabeblack@google.com // The node that used to be last is in front of t. 9912953Sgabeblack@google.com prevListNode->nextListNode = t; 10012953Sgabeblack@google.com 10112953Sgabeblack@google.com // Nobody is behind t. 10212953Sgabeblack@google.com t->nextListNode = this; 10312953Sgabeblack@google.com // The last node is t. 10412953Sgabeblack@google.com prevListNode = t; 10512953Sgabeblack@google.com } 10612953Sgabeblack@google.com 10712953Sgabeblack@google.com T *getNext() { return dynamic_cast<T *>(nextListNode); } 10812953Sgabeblack@google.com bool empty() { return getNext() == nullptr; } 10912953Sgabeblack@google.com}; 11012953Sgabeblack@google.com 11112953Sgabeblack@google.com} // namespace sc_gem5 11212953Sgabeblack@google.com 11312953Sgabeblack@google.com#endif //__SYSTEMC_CORE_LIST_HH__ 114