正在显示
1 个修改的文件
包含
62 行增加
和
0 行删除
src/server/spserver/spexecutor.hpp
0 → 100644
1 | +/* | |
2 | + * Copyright 2007 Stephen Liu | |
3 | + * For license terms, see the file COPYING along with this library. | |
4 | + */ | |
5 | + | |
6 | + | |
7 | +#ifndef __spexecutor_hpp__ | |
8 | +#define __spexecutor_hpp__ | |
9 | + | |
10 | +#include "spthread.hpp" | |
11 | + | |
12 | +class SP_ThreadPool; | |
13 | +class SP_BlockingQueue; | |
14 | + | |
15 | +class SP_Task { | |
16 | +public: | |
17 | + virtual ~SP_Task(); | |
18 | + virtual void run() = 0; | |
19 | +}; | |
20 | + | |
21 | +class SP_SimpleTask : public SP_Task { | |
22 | +public: | |
23 | + typedef void ( * ThreadFunc_t ) ( void * ); | |
24 | + | |
25 | + SP_SimpleTask( ThreadFunc_t func, void * arg, int deleteAfterRun ); | |
26 | + virtual ~SP_SimpleTask(); | |
27 | + | |
28 | + virtual void run(); | |
29 | + | |
30 | +private: | |
31 | + ThreadFunc_t mFunc; | |
32 | + void * mArg; | |
33 | + | |
34 | + int mDeleteAfterRun; | |
35 | +}; | |
36 | + | |
37 | +class SP_Executor { | |
38 | +public: | |
39 | + SP_Executor( int maxThreads, const char * tag = 0 ); | |
40 | + ~SP_Executor(); | |
41 | + | |
42 | + void execute( SP_Task * task ); | |
43 | + void execute( void ( * func ) ( void * ), void * arg ); | |
44 | + int getQueueLength(); | |
45 | + void shutdown(); | |
46 | + | |
47 | +private: | |
48 | + static void msgQueueCallback( void * queueData, void * arg ); | |
49 | + static void worker( void * arg ); | |
50 | + static sp_thread_result_t SP_THREAD_CALL eventLoop( void * arg ); | |
51 | + | |
52 | + SP_ThreadPool * mThreadPool; | |
53 | + SP_BlockingQueue * mQueue; | |
54 | + | |
55 | + int mIsShutdown; | |
56 | + | |
57 | + sp_thread_mutex_t mMutex; | |
58 | + sp_thread_cond_t mCond; | |
59 | +}; | |
60 | + | |
61 | +#endif | |
62 | + | ... | ... |
请
注册
或
登录
后发表评论