当前位置: 首页>>代码示例>>C++>>正文


C++ Stub::IncRef方法代码示例

本文整理汇总了C++中Stub::IncRef方法的典型用法代码示例。如果您正苦于以下问题:C++ Stub::IncRef方法的具体用法?C++ Stub::IncRef怎么用?C++ Stub::IncRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stub的用法示例。


在下文中一共展示了Stub::IncRef方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CompileMLStub

//---------------------------------------------------------
// Returns the equivalent hashed Stub, creating a new hash
// entry if necessary. If the latter, will call out to CompileMLStub.
//
// Refcounting:
//    The caller is responsible for DecRef'ing the returned stub in
//    order to avoid leaks.
//
//
// On successful exit, *pMode is set to describe
// the compiled nature of the MLStub.
//
// callerContext can be used by the caller to push some context through
// to the compilation routine.
//
// Returns NULL for out of memory or other fatal error.
//---------------------------------------------------------
Stub *MLStubCache::Canonicalize(const BYTE * pRawMLStub, MLStubCompilationMode *pMode,
                                void *callerContext)
{
    m_crst.Enter();

    MLCHASHENTRY *phe = (MLCHASHENTRY*)Find((LPVOID)pRawMLStub);
    if (phe) {
        Stub *pstub = phe->m_pMLStub;
        pstub->IncRef();
        *pMode = (MLStubCompilationMode) (phe->m_compilationMode);
        m_crst.Leave();
        return pstub;
    }
    m_crst.Leave();

    {
        CPUSTUBLINKER sl;
        CPUSTUBLINKER slempty;
        CPUSTUBLINKER *psl = &sl;
        MLStubCompilationMode mode;
        mode = CompileMLStub(pRawMLStub, psl, callerContext);
        if (mode == INTERPRETED) {
            // CompileMLStub returns INTERPRETED for error cases:
            // in this case, redirect to the empty stublinker so
            // we don't accidentally pick up any crud that
            // CompileMLStub threw into the stublinker before
            // it ran into the error condition.
            psl = &slempty;
        }

        *pMode = mode;

        UINT32 offset;
        Stub   *pstub;
        if (NULL == (pstub = FinishLinking(psl, pRawMLStub, &offset))) {
            return NULL;
        }

        if (offset > 0xffff) {
            return NULL;
        }

        m_crst.Enter();

        bool bNew;
        phe = (MLCHASHENTRY*)FindOrAdd((LPVOID)pRawMLStub, /*modifies*/bNew);
        if (phe) {
            if (bNew) {
                // Note: FinishLinking already does the IncRef.
                phe->m_pMLStub = pstub;
                phe->m_offsetOfRawMLStub = (UINT16)offset;
                phe->m_compilationMode   = mode;

            } else {

                // If we got here, some other thread got in
                // and enregistered an identical stub during
                // the window in which we were out of the m_crst.

                //Under DEBUG, two identical ML streams can actually compile
                // to different compiled stubs due to the checked build's
                // toggling between inlined TLSGetValue and api TLSGetValue.
                //_ASSERTE(phe->m_offsetOfRawMLStub == (UINT16)offset);
                _ASSERTE(phe->m_compilationMode == mode);
                pstub->DecRef(); // Destroy the stub we just created
                pstub = phe->m_pMLStub; //Use the previously created stub

            }

            // IncRef so that caller has firm ownership of stub.
            pstub->IncRef();
        }

        m_crst.Leave();

        if (phe) {
            return pstub;
        } else {
            // Couldn't grow hash table due to lack of memory.
            // Destroy the stub and return NULL.
            pstub->DecRef();
        }

//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:mlcache.cpp


注:本文中的Stub::IncRef方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。