2009/06/04
1.涉及的組件使用C++Builder開發(fā)固定流程的IVR。
來話后放音,循環(huán)放音完成后掛機(jī)。
////////////////////////////////////////////////////////////
FindCallByID(m_OriginalCallID);
class CThreadManager
{
private:
TBucketList *m_pThreadList; //線程列表哈希表
TCriticalSection *m_pListLocker; //線程鎖
public:
CThreadManager();
~CThreadManager();
//將線程加入線程表
void AddThread(TThread *pThd);
//根據(jù)線程ID從線程中移除
void RemoveThreadByThreadID(int ThreadID);
//根據(jù)線程ID查找線程對象
TThread *FindThreadByThreadID(int ThreadID);
};
//線程管理器構(gòu)造
CThreadManager::CThreadManager()
{
m_pThreadList = new TBucketList(bl16);
m_pListLocker = new TCriticalSection();
}
//線程管理器析構(gòu)
CThreadManager::~CThreadManager()
{
delete m_pThreadList;
delete m_pListLocker;
}
//加入線程列表
void CThreadManager::AddThread(TThread *pThd)
{
//多線程訪問列表,需要加鎖
m_pListLocker->Acquire();
try
{
m_pThreadList->Add((void*)(pThd->ThreadID), pThd);
}
catch(...)
{
}
m_pListLocker->Release();
}
//從線程列表中刪除
void CThreadManager::RemoveThreadByThreadID(int ThreadID)
{
//多線程訪問列表,需要加鎖
m_pListLocker->Acquire();
try
{
TThread *pThd = NULL;
if (m_pThreadList->Find((void*)ThreadID, (void*)pThd))
{
m_pThreadList->Remove((void*)ThreadID);
}
}
catch(...)
{
}
m_pListLocker->Release();
}
//根據(jù)線程ID查找線程
TThread * CThreadManager::FindThreadByThreadID(int ThreadID)
{
TThread *pRetThd = NULL;
//多線程訪問列表,需要加鎖
m_pListLocker->Acquire();
try
{
TThread *pThd = NULL;
if (m_pThreadList->Find((void*)ThreadID, (void*)pThd))
{
pRetThd = pThd;
}
}
catch(...)
{
}
m_pListLocker->Release();
return pRetThd;
}
CTI論壇報(bào)道