本文整理汇总了C++中ITask::Ptskctxt方法的典型用法代码示例。如果您正苦于以下问题:C++ ITask::Ptskctxt方法的具体用法?C++ ITask::Ptskctxt怎么用?C++ ITask::Ptskctxt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITask
的用法示例。
在下文中一共展示了ITask::Ptskctxt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: amp
//---------------------------------------------------------------------------
// @function:
// CAutoTaskProxy::PtskCreate
//
// @doc:
// Create new task;
// Bind task to function and argument and associate with task and error context;
// If caller is a task, its task context is cloned and used by the new task;
//
//---------------------------------------------------------------------------
CTask *
CAutoTaskProxy::PtskCreate
(
void *(*pfunc)(void*),
void *pvArg,
volatile BOOL *pfCancel
)
{
// create memory pool for task
CAutoMemoryPool amp(CAutoMemoryPool::ElcStrict);
IMemoryPool *pmp = amp.Pmp();
// auto pointer to hold new task context
CAutoP<CTaskContext> aptc;
// check if caller is a task
ITask *ptskParent = CWorker::PwrkrSelf()->Ptsk();
if (NULL == ptskParent)
{
// create new task context
aptc = GPOS_NEW(pmp) CTaskContext(pmp);
}
else
{
// clone parent task's context
aptc = GPOS_NEW(pmp) CTaskContext(pmp, *ptskParent->Ptskctxt());
}
// auto pointer to hold error context
CAutoP<CErrorContext> apec;
apec = GPOS_NEW(pmp) CErrorContext();
CTask *ptsk = CTask::PtskSelf();
if (NULL != ptsk)
{
apec.Pt()->Register(ptsk->PerrctxtConvert()->Pmdr());
}
// auto pointer to hold new task
// task is created inside ATP's memory pool
CAutoP<CTask> apt;
apt = GPOS_NEW(m_pmp) CTask(pmp, aptc.Pt(), apec.Pt(), &m_event, pfCancel);
// reset auto pointers - task now handles task and error context
(void) aptc.PtReset();
(void) apec.PtReset();
// detach task's memory pool from auto memory pool
amp.PmpDetach();
// bind function and argument
ptsk = apt.Pt();
ptsk->Bind(pfunc, pvArg);
// add to task list
m_list.Append(ptsk);
// reset auto pointer - ATP now handles task
apt.PtReset();
// register task to worker pool
m_pwpm->RegisterTask(ptsk);
return ptsk;
}