sgpemv2/src/backend/ready_queue.cc
tchernobog 0f718f2899 - Fix all includes, separating header files to be installed
from other headers. Take it while it's hot.
- To all those that lock source files: you'll burn in hell. Really.
It'll be painful, dreadful and above all *long*. *Eternally* long.
And there'll be Freddy Mercury and The Queen playing, *all the time*, 
day after boring, useless, sorrowful day. The song
will be *``Radio Ga-Ga''*, in secula secularum amen.


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1033 3ecf2c5c-341e-0410-92b4-d18e462d057c
2006-09-07 00:43:00 +00:00

92 lines
2 KiB
C++

// src/backend/resource.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "config.h"
#include "gettext.h"
#include <sgpemv2/ready_queue.hh>
using sgpem::ReadyQueue;
void
ReadyQueue::swap(position a, position b)
throw (std::out_of_range)
{
if (a == b) return;
// Usage of "at()" isn't casual:
// at() checks indexes, "[]" doesn't.
// Once we've done the check once, we
// can assume it's safe to use "[]";
// this for performance reasons.
Thread* temp = _scheds.at(a);
_scheds[a] = _scheds.at(b);
_scheds[b] = temp;
}
ReadyQueue::size_t
ReadyQueue::size() const
{
return _scheds.size();
}
sgpem::Thread&
ReadyQueue::get_item_at(position index)
throw (std::out_of_range)
{
// Checks index access
return *_scheds.at(index);
}
const sgpem::Thread&
ReadyQueue::get_item_at(position index) const
throw (std::out_of_range)
{
// Checks index access
return *_scheds.at(index);
}
void
ReadyQueue::append(Thread& thread)
{
_scheds.push_back(&thread);
}
void
ReadyQueue::bubble_to_front(position x)
throw(std::out_of_range)
{
while(x > 0)
{
swap(x - 1, x);
--x;
}
}
void
ReadyQueue::erase_first()
{
_scheds.erase(_scheds.begin());
}