提交 8f0b5bcf9301145bdc2705ef20c2b9c311aa9b55

作者 LJH 李佳桓
1 个父辈 7859f246

add

  1 +/*
  2 + * Copyright 2007 Stephen Liu
  3 + * For license terms, see the file COPYING along with this library.
  4 + */
  5 +
  6 +
  7 +#ifndef __spthreadpool_hpp__
  8 +#define __spthreadpool_hpp__
  9 +
  10 +#include "spthread.hpp"
  11 +
  12 +typedef struct tagSP_Thread SP_Thread_t;
  13 +
  14 +class SP_ThreadPool {
  15 +public:
  16 + typedef void ( * DispatchFunc_t )( void * );
  17 +
  18 + SP_ThreadPool( int maxThreads, const char * tag = 0 );
  19 + ~SP_ThreadPool();
  20 +
  21 + /// @return 0 : OK, -1 : cannot create thread
  22 + int dispatch( DispatchFunc_t dispatchFunc, void *arg );
  23 +
  24 + int getMaxThreads();
  25 +
  26 +private:
  27 + char * mTag;
  28 +
  29 + int mMaxThreads;
  30 + int mIndex;
  31 + int mTotal;
  32 + int mIsShutdown;
  33 +
  34 + sp_thread_mutex_t mMainMutex;
  35 + sp_thread_cond_t mIdleCond;
  36 + sp_thread_cond_t mFullCond;
  37 + sp_thread_cond_t mEmptyCond;
  38 +
  39 + SP_Thread_t ** mThreadList;
  40 +
  41 + static sp_thread_result_t SP_THREAD_CALL wrapperFunc( void * );
  42 + int saveThread( SP_Thread_t * thread );
  43 +};
  44 +
  45 +#endif
  46 +
... ...
注册登录 后发表评论