示例#1
0
////////////////////////////////////////////////////////////
//	最后释放掉所有资源
void IocpPool::_DeInitialize()
{
	// 删除客户端列表的互斥量
	DeleteCriticalSection(&m_csContextList);

	// 关闭系统退出事件句柄
	RELEASE_HANDLE(m_hShutdownEvent);

	// 释放工作者线程句柄指针
	for(unsigned int i=0;i<_works.size();i++ )
	{
		if (_works[i])
			_works[i]->stop();
	}
	if (check)
	{
		check->stop();
	}
	//RELEASE(m_phWorkerThreads);

	// 关闭IOCP句柄
	RELEASE_HANDLE(m_hIOCompletionPort);

	// 关闭监听Socket
	RELEASE(m_pListenContext);

//	this->_ShowMessage("释放资源完毕.\n");
}
示例#2
0
//////////////////////////////////////////////////////////////////////
//	清空资源
void CClient::CleanUp()
{
	if(m_hShutdownEvent==NULL) return;

	RELEASE(m_phWorkerThreads);

	RELEASE_HANDLE(m_hConnectionThread);

	RELEASE(m_pParamsWorker);

	RELEASE_HANDLE(m_hShutdownEvent);
}
示例#3
0
/**
 * Increments the global reference count of a managed value
 *
 * @pre h != NULL
 *
 * @post h->global_rc = h->global_rc@pre + 1
 *
 * @param Handle to update
 */
void PICC_handle_incr_ref_count(PICC_Handle *h)
{
    /* #ifdef CONTRACT_PRE_INV */
    /*     //inv */
    /*     PICC_Channel_inv(channel); */
    /* #endif */

    #ifdef CONTRACT_PRE
        //pre
        ASSERT(h != NULL );
    #endif

    #ifdef CONTRACT_POST
        // capture
        // int global_rc_at_pre = h->global_rc;
    #endif

    LOCK_HANDLE(h);
    h->global_rc++;
    RELEASE_HANDLE(h);

    /* #ifdef CONTRACT_POST_INV */
    /*     //inv */
    /*     PICC_Channel_inv(channel); */
    /* #endif */

    /* #ifdef CONTRACT_POST */
    /*     //post */
    /*     ASSERT(channel->global_rc == global_rc_at_pre + 1 );  */
    /*     // cannot be asserted ! as the lock is released we don't have any garanty */
    /* #endif */
}
示例#4
0
CIOCPModel::~CIOCPModel(void)
{
	// 确保资源彻底释放
	//this->Stop();
	// 删除客户端列表的互斥量
	DeleteCriticalSection(&m_csDataFile);
	//DeleteCriticalSection(&m_csChannel);

	// 关闭系统退出事件句柄
	RELEASE_HANDLE(m_hShutdownEvent);
}
示例#5
0
void CIOCP::_DeInitialize()
{
	// 删除客户端列表的互斥量
	DeleteCriticalSection(&m_csContextList);

	// 关闭系统退出事件句柄
	RELEASE_HANDLE(m_hShutdownEvent);

	// 释放工作者线程句柄指针
	for( int i=0;i<m_nThreads;i++ )
	{
		RELEASE_HANDLE(m_phWorkerThreads[i]);
	}
	
	RELEASE(m_phWorkerThreads);

	// 关闭IOCP句柄
	RELEASE_HANDLE(m_hIOCompletionPort);


	_LogInfo(L"释放资源完毕.\n");
}
示例#6
0
////////////////////////////////////////////////////////////
//	最后释放掉所有资源
void CIOCPModel::_DeInitialize()
{
	// 删除客户端列表的互斥量
	DeleteCriticalSection(&m_csContextList);

	// 关闭系统退出事件句柄
	RELEASE_HANDLE(m_hShutdownEvent);

	// 释放工作者线程句柄指针
	for( int i=0;i<m_nThreads;i++ )
	{
		RELEASE_HANDLE(m_phWorkerThreads[i]);
	}
	
	RELEASE(m_phWorkerThreads);

	// 关闭IOCP句柄
	RELEASE_HANDLE(m_hIOCompletionPort);

	// 关闭监听Socket
	RELEASE(m_pListenContext);

	//this->_ShowMessage("释放资源完毕.\n");
}
示例#7
0
////////////////////////////////////////////////////////////////////
//	开始发送系统退出消息,退出完成端口和线程资源
void CIOCPModel::Stop()
{
		// 激活关闭消息通知
		SetEvent(m_hShutdownEvent);

		//// 等待所有的客户端资源退出
		//WaitForMultipleObjects(m_nThreads, m_phWorkerThreads, TRUE, INFINITE);
		closesocket(m_ListenSocket);
		WSACleanup();
		TerminateThread(m_hThrdAccept, 0);
	

		// 删除客户端列表的互斥量
		DeleteCriticalSection(&m_csDataFile);
		DeleteCriticalSection(&m_csChannel);

		// 关闭系统退出事件句柄
		RELEASE_HANDLE(m_hShutdownEvent);

		//this->_ShowMessage("停止监听\n");
}
示例#8
0
/**
 * Decrements the global reference count of a managed value
 *
 * @pre h != NULL
 *
 * @post h->global_rc = h->global_rc@pre - 1
 *
 * @param Handle to update
 */
void PICC_handle_dec_ref_count(PICC_Handle **h)
{
    /* #ifdef CONTRACT_PRE_INV */
    /*     //inv */
    /*     PICC_Channel_inv(*channel); */
    /* #endif */

    #ifdef CONTRACT_PRE
        //pre
        ASSERT(*h != NULL );
    #endif

    #ifdef CONTRACT_POST
        // capture
        // int global_rc_at_pre = (*h)->global_rc;
    #endif

	// I think there is a problem here: what happens if global_rc is equal to one
	// and another thread was about to increment it but lost the race to acquire the lock ?
	//
	// moreover, for now the lock is alocated in the channel/handle with the previous
	// case in mind we cannot free it in the reclaim
	// I think a solution would be to have a pool of Lock witch contain the lock itself
	// and the value it's suposed to lock
	//
	// kind of:
	// struct{
	//   atomic_int cpt;
	//   void *content;
        // }
	//
	// in the function lock_alloc we would keep track of all the locks and we could
	// reuse the ones that have cpt == 0 && content == NULL
	//

    LOCK_HANDLE(*h);
    (*h)->global_rc--;

    if ((*h)->global_rc == 0) {
	RELEASE_HANDLE(*h);

	ALLOC_ERROR(reclaim_error);
        (*h)->reclaim(*h, &reclaim_error);
	*h = NULL;
        if (HAS_ERROR(reclaim_error))
            CRASH(&reclaim_error);
    }
    else{
	RELEASE_HANDLE(*h);
    }

    /* #ifdef CONTRACT_POST_INV */
    /*     if (*h != NULL) */
    /*         PICC_Channel_inv(*channel); */
    /* #endif */

    /* #ifdef CONTRACT_POST */
    /*     if(global_rc_at_pre > 1) */
    /*         ASSERT((*channel)->global_rc == global_rc_at_pre - 1 ); */
    //cannot be asserted see incr for the same comment
    /* #endif */
}