/// <summary> /// Prepares for execution as a stolen chore. /// </summary> void _UnrealizedChore::_PrepareStealUnstructured(ContextBase *pBaseContext) { InternalContextBase *pContext = static_cast<InternalContextBase *> (pBaseContext); if (pContext->GetRootCollection() == NULL) { _TaskCollection* pTaskCollection = static_cast<_TaskCollection *> (_M_pTaskCollection); ContextBase *pOriginContext = reinterpret_cast <ContextBase *> (pTaskCollection->_M_pOwningContext); pContext->SetRootCollection(pTaskCollection); // // pOriginContext is only safe to touch if the act of stealing from a non-detached context put a hold on that context // to block deletion until we are chained for cancellation. // SafeRWList<ListEntry> *pList = reinterpret_cast<SafeRWList<ListEntry> *> (pTaskCollection->_M_stealTracker); ASSERT(sizeof(pTaskCollection->_M_stealTracker) >= sizeof(*pList)); if (_M_fDetached) { // // We cannot touch the owning context -- it was detached as of the steal. The chain goes onto the task collection. // pContext->NotifyTaskCollectionChainedStealer(); pList->AddTail(&(pContext->m_stealChain)); } else { pList->AcquireWrite(); pTaskCollection->_M_activeStealersForCancellation++; pList->ReleaseWrite(); pOriginContext->AddStealer(pContext, true); } } }
/// <summary> /// Prepares for execution as a stolen chore. /// </summary> void _UnrealizedChore::_PrepareStealStructured(ContextBase *pBaseContext) { InternalContextBase *pContext = static_cast<InternalContextBase *> (pBaseContext); if (pContext->GetRootCollection() == NULL) { _StructuredTaskCollection *pTaskCollection = static_cast<_StructuredTaskCollection *> (_M_pTaskCollection); ContextBase *pOriginContext = reinterpret_cast <ContextBase *> (pTaskCollection->_M_pOwningContext); pContext->SetRootCollection(pTaskCollection); pOriginContext->AddStealer(pContext, false); } }