예제 #1
0
        public static tAsyncCall *set_Target(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tWeakRef *         pThis  = (tWeakRef *)pThis_;
            /*HEAP_PTR*/ byte *target = ((/*HEAP_PTR*/ byte **)pParams)[0];

            if (pThis->target != null)
            {
                tWeakRef **ppWeakRef = (tWeakRef **)Heap.GetWeakRefAddress(pThis->target);
                while (*ppWeakRef != null)
                {
                    tWeakRef *pWeakRef = *ppWeakRef;
                    if (pWeakRef == pThis)
                    {
                        *ppWeakRef = pWeakRef->pNextWeakRef;
                        Heap.RemovedWeakRefTarget(pWeakRef->target);
                        goto foundOK;
                    }
                    ppWeakRef = &(pWeakRef->pNextWeakRef);
                }
                Sys.Crash("WeakRef.set_Target() Error: cannot find weak-ref target for removal");
                foundOK :;
            }
            pThis->target = target;
            if (target != null)
            {
                pThis->pNextWeakRef = (tWeakRef *)Heap.SetWeakRefTarget(target, (/*HEAP_PTR*/ byte *)pThis);
            }

            return(null);
        }
예제 #2
0
        public static tAsyncCall *get_Target(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tWeakRef *pThis = (tWeakRef *)pThis_;

            *(/*HEAP_PTR*/ byte **)pReturnValue = pThis->target;
            return(null);
        }
예제 #3
0
        public static void TargetGone(/*HEAP_PTR*/ byte **ppWeakRef_, uint removeLongRefs)
        {
            tWeakRef **ppWeakRef = (tWeakRef **)ppWeakRef_;
            tWeakRef * pWeakRef  = *ppWeakRef;

            while (pWeakRef != null)
            {
                if (removeLongRefs != 0 || pWeakRef->trackRes == 0)
                {
                    // Really remove it
                    pWeakRef->target = null;
                }
                else
                {
                    // Long ref, so keep it
                    *ppWeakRef = pWeakRef;
                    ppWeakRef = &(pWeakRef->pNextWeakRef);
                }
                pWeakRef = pWeakRef->pNextWeakRef;
            }
            *ppWeakRef = null;
        }