00001 //------------------------------------------------------------------------------ 00002 // Lamp : Open source game middleware 00003 // Copyright (C) 2004 Junpei Ohtani ( Email : junpee@users.sourceforge.jp ) 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 //------------------------------------------------------------------------------ 00019 00020 /** @file 00021 * 実行可能ヘッダ 00022 * @author Junpee 00023 */ 00024 00025 #ifndef RUNNABLE_H_ 00026 #define RUNNABLE_H_ 00027 00028 #include <Core/Thread/WaitSet.h> 00029 00030 namespace Lamp{ 00031 00032 class Thread; 00033 00034 //------------------------------------------------------------------------------ 00035 /** 00036 * 実行可能 00037 */ 00038 class Runnable : public WaitSet{ 00039 friend class Thread; 00040 public: 00041 /** 00042 * コンストラクタ 00043 */ 00044 Runnable() : WaitSet(), stopRequested_(false){} 00045 00046 /** 00047 * コンストラクタ 00048 * @param lockObject ロックオブジェクト 00049 * @param deleteLockObject ロックオブジェクトをWaitSetが削除するならtrue 00050 */ 00051 Runnable(LockObject* lockObject, bool deleteLockObject) : 00052 WaitSet(lockObject, deleteLockObject), stopRequested_(false){} 00053 00054 /** 00055 * デストラクタ 00056 */ 00057 virtual ~Runnable(){} 00058 00059 /** 00060 * 停止を要求されているか 00061 * @return 停止を要求されていればtrue 00062 */ 00063 bool isStopRequested() const{ return stopRequested_; } 00064 00065 /** 00066 * 実行 00067 * @param thread 実行しているスレッド 00068 * 00069 * isStopRequested()がtrueを返す場合は速やかに処理を終了させる 00070 */ 00071 virtual void run(Thread* thread) = 0; 00072 00073 private: 00074 // 停止要求フラグの設定 00075 void setStopRequested(bool stopRequested){ 00076 stopRequested_ = stopRequested; 00077 } 00078 00079 // 停止要求 00080 volatile bool stopRequested_; 00081 00082 }; 00083 00084 //------------------------------------------------------------------------------ 00085 } // End of namespace Lamp 00086 #endif // End of RUNNABLE_H_ 00087 //------------------------------------------------------------------------------