📄 scheduler.h
字号:
//// Copyright (c) 2003 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program 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.//// This program 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 this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#ifndef DXR3PLAYER_DVD_VM_SCHEDULER_H#define DXR3PLAYER_DVD_VM_SCHEDULER_H//------------------------------------------------------------------------------#include "dvd/vm/InstructionSet.h"#include "dvd/vm/Position.h"#include "defs.h"//------------------------------------------------------------------------------namespace dvd { namespace vm {//------------------------------------------------------------------------------class Processor;//------------------------------------------------------------------------------/** * Instruction scheduler. */class Scheduler{private: /** * The size of the command stack. */ static const size_t commandStackSize = 10;public: /** * Command for the instruction scheduler. */ class Command { protected: /** * The scheduler the command belongs to */ Scheduler& scheduler; public: /** * Construct the command for the given scheduler. */ Command(Scheduler& scheduler); /** * Execute the command. */ virtual void execute() const = 0; }; /** * Command setting up an instruction set to be executed from a * given starting point. */ class InstructionSetCommand : public Command { private: /** * The instruction set to be used. */ InstructionSet instructionSet; /** * The starting instruction pointer. */ size_t instructionPointer; public: /** * Construct the command. */ InstructionSetCommand(Scheduler& scheduler, const InstructionSet& instructionSet, size_t instructionPointer); /** * Execute the command. */ virtual void execute() const; }; /** * Command executing the instruction pointed to by the instruction * pointer and advancing the pointer. */ class StepCommand : public Command { public: /** * Construct the command. */ StepCommand(Scheduler& scheduler); /** * @see Command::execute */ virtual void execute() const; }; /** * Command setting the instruction pointer to a given value. */ class GotoCommand : public Command { private: /** * The new instruction pointer. */ size_t instructionPointer; public: /** * Construct the goto command. */ GotoCommand(Scheduler& scheduler, size_t instructionPointer); /** * @see Command::execute */ virtual void execute() const; }; /** * Command breaking the execution of the current instruction set. */ class BreakCommand : public Command { public: /** * Construct the goto command. */ BreakCommand(Scheduler& scheduler); /** * @see Command::execute */ virtual void execute() const; }; /** * Command setting the position to the given value. */ class SetPositionCommand : public Command { private: /** * The target position. */ Position position; public: /** * Construct the goto command. */ SetPositionCommand(Scheduler& scheduler, const Position& position); /** * @see Command::execute */ virtual void execute() const; }; friend class InstructionSetCommand; friend class StepCommand; friend class GotoCommand; friend class BreakCommand; friend class SetPositionCommand;private: /** * The processor the scheduler belongs to. */ Processor& processor; /** * The command stack. The last one is always executed first. */ const Command* commandStack[commandStackSize]; /** * The pointer to the next empty element. */ size_t nextCommandSlot; /** * The instruction set currently used. */ InstructionSet instructionSet; /** * The instruction pointer. */ size_t instructionPointer;public: /** * Construct the scheduler. */ Scheduler(Processor& processor); /** * Flush the commands. */ void flush(); /** * Add an instruction set command. */ void addInstructionSet(const Instruction* instructions, size_t length = 1, size_t insPointer = 0); /** * Add an instruction set command for the command associated with * the cell pointed to by the given position. * * @return if there was a command for the cell */ bool addCellCommand(const Position& position); /** * Add an instruction set command for the pre-commands associated with * the PGC pointed to by the given position. If the PGC is * invalid, the first play PGC will be added. * * @return if the PGC was invalid */ bool addPGCPreCommands(const Position& position); /** * Flush the scheduler, add an instruction set command for the * pre-commands associated with the PGC pointed to by the given * position and add a position setting command. If the PGC is * invalid, the first play PGC will be added. * * @return if the PGC was valid */ bool addStartPGC(const Position& position); /** * Add an instruction set command for the post-commands associated with * the PGC pointed to by the given position. * * @return if there were commands */ bool addPGCPostCommands(const Position& position); /** * Add a step command. */ void addStep(); /** * Add a goto command. */ void addGoto(size_t insPointer); /** * Add a break command. */ void addBreak(); /** * Add a set position command. */ void addSetPosition(const Position& position); /** * Add commands to go to the first play PGC. */ void addFirstPlayPGC(); /** * Run the scheduler. */ void run();private: /** * Add a command to the command stack. If fails, flush and * go to the first play PGC. */ void push(const Command* command); /** * Pop the last command from the stack, if any. If no command, * return 0. */ const Command* pop(); /** * Execute the instruction pointed to by the instruction pointer, * and advance the instruction pointer. */ void step(); /** * Break the current instruction set. */ void breakSet(); /** * Set the given position. */ void setPosition(const Position& position);};//------------------------------------------------------------------------------//------------------------------------------------------------------------------// Inline definitions//------------------------------------------------------------------------------inline Scheduler::Command::Command(Scheduler& scheduler) : scheduler(scheduler){}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline Scheduler::InstructionSetCommand::InstructionSetCommand(Scheduler& scheduler, const InstructionSet& instructionSet, size_t instructionPointer) : Command(scheduler), instructionSet(instructionSet), instructionPointer(instructionPointer){}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline Scheduler::StepCommand::StepCommand(Scheduler& scheduler) : Command(scheduler){}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline Scheduler::GotoCommand::GotoCommand(Scheduler& scheduler, size_t instructionPointer) : Command(scheduler), instructionPointer(instructionPointer){}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline Scheduler::BreakCommand::BreakCommand(Scheduler& scheduler) : Command(scheduler){}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline Scheduler::SetPositionCommand::SetPositionCommand(Scheduler& scheduler, const Position& position) : Command(scheduler), position(position){}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline Scheduler::Scheduler(Processor& processor) : processor(processor), nextCommandSlot(0){}//------------------------------------------------------------------------------//------------------------------------------------------------------------------//------------------------------------------------------------------------------} /* namespace dvd::vm */ } /* namespace dvd *///------------------------------------------------------------------------------#endif // DXR3PLAYER_DVD_VM_SCHEDULER_H// Local variables:// mode: c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -