📄 thread.h
字号:
/*============================================================================. | Copyright (C) 2006 Gareth Buxton | |----------------------------------------------------------------------------| | LogPlusPlus is free software; you can redistribute it and/or | | modify it under the terms of the GNU Lesser General Public | | License as published by the Free Software Foundation; either | | version 2.1 of the License, or (at your option) any later version. | | | | LogPlusPlus 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 | | Lesser General Public License for more details. | | | | You should have received a copy of the GNU Lesser General Public | | License along with this library; if not, write to the Free Software | | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | '============================================================================*/#ifndef _LPP_THREAD_H_#define _LPP_THREAD_H_#include <liblpp/Types.h>//#include <liblpp/Log.h>//=============================================================================LPP_NAMESPACE_BEGIN//=============================================================================class Runnable{public: virtual void run() = 0; virtual void end() = 0; virtual ~Runnable(){}};class Thread: public Runnable{private: //const Log& log;protected: Runnable& runnable; Thread(); void run(); void end(); public: Thread(Runnable& runnable); virtual ~Thread(); /** * This method should be implemented to * provide a mutex function. ie. only one * thread at a time should be able to * call this method without blocking until * the corresponding call to unlock() is * made by that same thread. All other * thread callers to this method will block. **/ virtual void lock() = 0; /** * This method should be implemented such that * it will allow the next thread waiting to enter * the lock() method to proceed. **/ virtual void unlock() = 0; /** * The implementation of this method should * cause the current executing thread to * yield control to other threads. **/ virtual void yield() = 0; /** * This method should perform a join to the implementer's * desired thread. Ie it should not return untill * an implementer dependent thread has terminated. **/ virtual void join() = 0; /** * This method should call the blocking method * void run() on a new thread. **/ virtual void start() = 0; /** * This method shuold call the blocking method * void end(). **/ virtual void stop() = 0; /** * This method shuold wait for an internal * signal to be made. After returning * the calling thread has the lock so MUST * call unlock() when finnished. * * NOTE: Caller SHOULD call lock() before * calling this method. **/ virtual void wait() = 0; // condition variabe /** * This method shuuld signal all threads waiting * for a signal through the wait() method. **/ virtual void signal() = 0; // condition wakeup};class ThreadMill{public: virtual ~ThreadMill(){} virtual Thread* create(Runnable& runnable) const = 0;};//=============================================================================LPP_NAMESPACE_END//=============================================================================#endif /*_LPP_THREAD_H_*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -