Click here to Skip to main content
15,896,557 members
Articles / Programming Languages / C++

A Simple and Easy to Use IOCP Server Framework

Rate me:
Please Sign up or sign in to vote.
3.43/5 (8 votes)
30 Jun 2008LGPL33 min read 44.2K   1.7K   35  
An introduction to SPServer Framework
/*
 * Copyright 2007 Stephen Liu
 * For license terms, see the file COPYING along with this library.
 */


#ifndef __spthreadpool_hpp__
#define __spthreadpool_hpp__

#include "spthread.hpp"

typedef struct tagSP_Thread SP_Thread_t;

class SP_ThreadPool {
public:
	typedef void ( * DispatchFunc_t )( void * );

	SP_ThreadPool( int maxThreads, const char * tag = 0 );
	~SP_ThreadPool();

	/// @return 0 : OK, -1 : cannot create thread
	int dispatch( DispatchFunc_t dispatchFunc, void *arg );

	int getMaxThreads();

private:
	char * mTag;

	int mMaxThreads;
	int mIndex;
	int mTotal;
	int mIsShutdown;

	sp_thread_mutex_t mMainMutex;
	sp_thread_cond_t mIdleCond;
	sp_thread_cond_t mFullCond;
	sp_thread_cond_t mEmptyCond;

	SP_Thread_t ** mThreadList;

	static sp_thread_result_t SP_THREAD_CALL wrapperFunc( void * );
	int saveThread( SP_Thread_t * thread );
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions