📄 threadservice.h
字号:
#ifndef __GradSoft_ThreadService_h#define __GradSoft_ThreadService_h/* * part of GradSoft C++ ToolBox * (C) GradSoft 2000, 2001 * http://www.gradsoft.com.ua * $Id: ThreadService.h,v 1.7 2001/10/31 03:13:47 rssh Exp $ */#ifndef __GradSoft_AtomicBool_h#include <GradSoft/AtomicBool.h>#endif#ifndef __GradSoft_Runnable_h#include <GradSoft/Runnable.h>#endifnamespace GradSoft {/** * ThreadService: entity which process Runnable * (Runnable may be events, network connections, etc) * Typical usage pattern: * 1. Generator generates Runnable * 2. this Runnables are passed to ThreadServices, * with help of call ThreadService::process * 3. ThreadService process this runnable, asynchronicly or * synchronisly. * * ThreadService can be in active or inactive state. * When it in active state, it can process requests. * When in inactive - can't. * **/class ThreadService{public: /** * This exception is throwed, when we try to use * not-activated ThreadService **/ struct NotActive {int dummy;};private: volatile AtomicBool active_;public: /// ThreadService(); /// virtual ~ThreadService(); /// virtual void process(Runnable* runnable)=0; /// bool is_active() const { return active_.value(); } /// virtual void activate(); /// virtual void deactivate(bool shutdown);protected: virtual void mark_deactivate(); class DeactivateRunnable: public Runnable { ThreadService* owner_p_; public: DeactivateRunnable(ThreadService* owner_p) :owner_p_(owner_p) {} void run() { owner_p_->mark_deactivate(); delete this; } }; friend DeactivateRunnable;private: ThreadService(const ThreadService&); ThreadService& operator=(const ThreadService&);};}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -