Пример #1
0
bool CIOCP::_InitializeIOCP()
{
	// 建立第一个完成端口
	m_hIOCompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0 );

	if ( NULL == m_hIOCompletionPort)
	{
		this->_LogInfo(_T("建立完成端口失败!错误代码: %d!\n"), WSAGetLastError());
		return false;
	}

	m_nThreads = WORKER_THREADS_PER_PROCESSOR * _GetNoOfProcessors();
	

	m_phWorkerThreads = new HANDLE[m_nThreads];

	DWORD nThreadID;
	for (int i = 0; i < m_nThreads; i++)
	{
		THREADPARAMS_WORKER* pThreadParams = new THREADPARAMS_WORKER;
		pThreadParams->pIOCPModel = this;
		pThreadParams->nThreadNo  = i+1;
		m_phWorkerThreads[i] = ::CreateThread(0, 0, _WorkerThread, (void *)pThreadParams, 0, &nThreadID);
	}

	_LogInfo(L" 建立 _WorkerThread %d 个.\n", m_nThreads );

	return true;
}
Пример #2
0
////////////////////////////////
// 初始化完成端口
bool CIOCPModel::_InitializeIOCP()
{
	// 建立第一个完成端口
	m_hIOCompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0 );

	if ( NULL == m_hIOCompletionPort)
	{
		//this->_ShowMessage(_T("建立完成端口失败!错误代码: %d!\n"), WSAGetLastError());
		return false;
	}

	// 根据本机中的处理器数量,建立对应的线程数
	m_nThreads = WORKER_THREADS_PER_PROCESSOR * _GetNoOfProcessors();
	
	// 为工作者线程初始化句柄
	m_phWorkerThreads = new HANDLE[m_nThreads];
	
	// 根据计算出来的数量建立工作者线程
	DWORD nThreadID;
	for (int i = 0; i < m_nThreads; i++)
	{
		THREADPARAMS_WORKER* pThreadParams = new THREADPARAMS_WORKER;
		pThreadParams->pIOCPModel = this;
		pThreadParams->nThreadNo  = i+1;
		m_phWorkerThreads[i] = ::CreateThread(0, 0, _WorkerThread, (void *)pThreadParams, 0, &nThreadID);
	}

	//TRACE(" 建立 _WorkerThread %d 个.\n", m_nThreads );

	return true;
}
Пример #3
0
////////////////////////////////
// 初始化完成端口
bool IocpPool::_InitializeIOCP()
{
	// 建立第一个完成端口
	m_hIOCompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0 );

	if ( NULL == m_hIOCompletionPort)
	{
		//this->_ShowMessage(_T("建立完成端口失败!错误代码: %d!\n"), WSAGetLastError());
		return false;
	}

	// 根据本机中的处理器数量,建立对应的线程数
int	m_nThreads = WORKER_THREADS_PER_PROCESSOR * _GetNoOfProcessors();
	
	// 为工作者线程初始化句柄
	//m_phWorkerThreads = new HANDLE[m_nThreads];
	
	// 根据计算出来的数量建立工作者线程
	//DWORD nThreadID;
	for (int i = 0; i < m_nThreads; i++)
	{
		IocpWorkThread * work = new IocpWorkThread(this);
		_works.push_back(work);
		work->start();
	}
	check = new CheckValidThread(this);
	check->start();
//	TRACE(" 建立 _WorkerThread %d 个.\n", m_nThreads );

	return true;
}