BOOL CDBPoolChk::InitSessionPool(UINT nReserve)
{
m_vecSession.reserve(nReserve);
for(UINT n=0;n<nReserve;n++)
AllocSession();
return TRUE;
}
BOOL CDBPoolChk::AllocSession()
{
CSession* pSession = new CSession();
if ( FAILED(pSession->Open(_db)) )
{
delete pSession;
return FALSE;
}
m_vecSession.push_back(pSession);
return TRUE;
}
BOOL CDBPoolChk::TermSessionPool()
{
for each(CSession* it in m_vecSession)
{
it->Close();
delete(it);
}
m_vecSession.clear();
return TRUE;
}
CSession* CDBPoolChk::GetSession()
{
EnterCriticalSection(&m_CS);
if ( 0 >= m_vecSession.size() )
{
// 세션 추가~
AllocSession();
}
CSession* pSession = m_vecSession.back();
m_vecSession.pop_back();
LeaveCriticalSection(&m_CS);
return pSession;
}
BOOL CDBPoolChk::FreeSession(CSession* pSession)
{
EnterCriticalSection(&m_CS);
m_vecSession.push_back(pSession);
LeaveCriticalSection(&m_CS);
return TRUE;
}
댓글을 달아 주세요