⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spexecutor.hpp

📁 spserver 是一个实现了半同步/半异步(Half-Sync/Half-Async)和领导者/追随者(Leader/Follower) 模式的服务器框架
💻 HPP
字号:
/* * Copyright 2007 Stephen Liu * For license terms, see the file COPYING along with this library. */#ifndef __spexecutor_hpp__#define __spexecutor_hpp__#include <pthread.h>class SP_ThreadPool;class SP_Task {public:	virtual ~SP_Task();	virtual void run() = 0;};class SP_SimpleTask : public SP_Task {public:	typedef void ( * ThreadFunc_t ) ( void * );	SP_SimpleTask( ThreadFunc_t func, void * arg, int deleteAfterRun );	virtual ~SP_SimpleTask();	virtual void run();private:	ThreadFunc_t mFunc;	void * mArg;	int mDeleteAfterRun;};class SP_Executor {public:	SP_Executor( int maxThreads, const char * tag = 0 );	~SP_Executor();	void execute( SP_Task * task );	void execute( void ( * func ) ( void * ), void * arg );	int getQueueLength();	void shutdown();private:	static void msgQueueCallback( void * queueData, void * arg );	static void worker( void * arg );	static void * eventLoop( void * arg );	SP_ThreadPool * mThreadPool;	void * mQueue;	void * mEventBase;	int mIsShutdown;	pthread_mutex_t mMutex;	pthread_cond_t mCond;};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -