?? waitcondition.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_SCHED_WAITCONDITION_H#define DXR3PLAYER_SCHED_WAITCONDITION_H//------------------------------------------------------------------------------#include <cstdlib>#include <cstring>#include <cassert>//------------------------------------------------------------------------------namespace sched {//------------------------------------------------------------------------------class Schedulable;//------------------------------------------------------------------------------/** * Waiting condition. It describes when the waiting can be finished, * because the condition a schedulable has been waiting for is fulfilled. */class WaitCondition{private: /** * The name of the wait condition's owner. */ const char* ownerName; /** * The name of the wait condition. */ const char* name; /** * The schedulable waiting on the condition. */ Schedulable* waiter; /** * Indicate if the condition has been fulfilled. */ bool fulfilled;public: /** * Construct the condition assigned to the given object having the * given name. */ WaitCondition(const char* ownerName, const char* name); /** * Get the owner's name. */ const char* getOwnerName() const; /** * Get the name. */ const char* getName() const; /** * Set the condition. */ void set(); /** * Check if the condition is fulfilled. */ bool check() const; /** * Check if the condition has a waiter. */ bool hasWaiter() const;private: /** * Initialize the condition. It clears the fulfilment indicater * and sets the waiter. */ void init(Schedulable* w, bool f = false); /** * Clear the condition and the waiter. * * @return if the condition had been fulfilled */ bool clear(); friend class Schedulable;};//------------------------------------------------------------------------------// Inline definitions//------------------------------------------------------------------------------inline WaitCondition::WaitCondition(const char* ownerName, const char * name) : ownerName(ownerName), name(name), waiter(0), fulfilled(false){}//------------------------------------------------------------------------------inline const char* WaitCondition::getOwnerName() const{ return ownerName;}//------------------------------------------------------------------------------inline const char* WaitCondition::getName() const{ return name;}//------------------------------------------------------------------------------inline void WaitCondition::set(){ if (waiter!=0) { fulfilled = true; }}//------------------------------------------------------------------------------inline bool WaitCondition::check() const{ return waiter!=0 && fulfilled;}//------------------------------------------------------------------------------inline bool WaitCondition::hasWaiter() const{ return waiter!=0;}//------------------------------------------------------------------------------inline void WaitCondition::init(Schedulable* w, bool f){ assert(!hasWaiter()); waiter = w; fulfilled = f;}//------------------------------------------------------------------------------inline bool WaitCondition::clear(){ bool f = fulfilled; waiter = 0; fulfilled = false; return f;}//------------------------------------------------------------------------------} /* namespace sched *///------------------------------------------------------------------------------#endif // DXR3PLAYER_SCHED_WAITCONDITION_H// Local variables:// mode: c++// End:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -