pktfifo.hh revision 1762
12SN/A/* 21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A */ 282665SN/A 292665SN/A#ifndef __DEV_PKTFIFO_HH__ 302SN/A#define __DEV_PKTFIFO_HH__ 312SN/A 321400SN/A#include <iosfwd> 331400SN/A#include <list> 342SN/A#include <string> 351298SN/A 361298SN/A#include "dev/etherpkt.hh" 378229Snate@binkert.org#include "sim/serialize.hh" 381298SN/A 398229Snate@binkert.orgclass Checkpoint; 408229Snate@binkert.orgclass PacketFifo 415034SN/A{ 421400SN/A protected: 431400SN/A std::list<PacketPtr> fifo; 441298SN/A int _maxsize; 45695SN/A int _size; 462SN/A int _reserved; 473187SN/A 483187SN/A public: 492SN/A explicit PacketFifo(int max) : _maxsize(max), _size(0), _reserved(0) {} 502SN/A virtual ~PacketFifo() {} 515034SN/A 525034SN/A int packets() const { return fifo.size(); } 532SN/A int maxsize() const { return _maxsize; } 543187SN/A int size() const { return _size; } 553187SN/A int reserved() const { return _reserved; } 562SN/A int avail() const { return _maxsize - _size - _reserved; } 572SN/A bool empty() const { return size() <= 0; } 581634SN/A bool full() const { return avail() <= 0; } 595100SN/A 601634SN/A int reserve(int len = 0) 612SN/A { 622SN/A _reserved += len; 632SN/A assert(avail() >= 0); 643187SN/A return _reserved; 653187SN/A } 665315SN/A 675315SN/A bool push(PacketPtr ptr) 685315SN/A { 695315SN/A assert(_reserved <= ptr->length); 705314SN/A if (avail() < ptr->length - _reserved) 715314SN/A return false; 722SN/A 732SN/A _size += ptr->length; 742SN/A fifo.push_back(ptr); 752SN/A _reserved = 0; 762SN/A return true; 775606SN/A } 782SN/A 795606SN/A PacketPtr front() { return fifo.front(); } 805606SN/A 815336SN/A void pop() 822SN/A { 832SN/A if (empty()) 842SN/A return; 854474SN/A 863187SN/A _size -= fifo.front()->length; 873187SN/A fifo.front() = NULL; 883187SN/A fifo.pop_front(); 893187SN/A } 903187SN/A 913187SN/A void clear() 923187SN/A { 933402SN/A fifo.clear(); 943187SN/A _size = 0; 953187SN/A _reserved = 0; 963187SN/A } 973187SN/A 983349SN/A/** 993187SN/A * Serialization stuff 1003349SN/A */ 1013187SN/A public: 1023349SN/A void serialize(const std::string &base, std::ostream &os); 1033187SN/A void unserialize(const std::string &base, 1048711Sandreas.hansson@arm.com Checkpoint *cp, const std::string §ion); 1053187SN/A}; 1063187SN/A 1073187SN/A#endif // __DEV_PKTFIFO_HH__ 1083187SN/A