Ejemplo n.º 1
0
    /// <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);
            }
        }
    }
Ejemplo n.º 2
0
    /// <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);
        }
    }