Exemplo n.º 1
0
        internal void Swap()
        {
            while (Interlocked.CompareExchange(ref pendingSlot, 1, 0) != 0)
            {
                ;
            }
            //inactive = Interlocked.Exchange(ref active, inactive);
            ResourceProperties temp = active;

            active   = inactive;
            inactive = temp;
            Interlocked.Decrement(ref pendingSlot);
        }
Exemplo n.º 2
0
        public void Unload(IEvent evt)
        {
            while ((Interlocked.CompareExchange(ref pendingOperation, 1, 0) == 1))
            {
                ;
            }

            switch (inactive.state)
            {
            case ResourceState.Ready:
                while (inactive.resource.IsAcquired)
                {
                    ;
                }
                inactive.state = ResourceState.Unloading;
                resourceLoader.Unload(this, evt);
                return;

            case ResourceState.Empty:
                switch (active.state)
                {
                case ResourceState.Ready:
                    while (Interlocked.CompareExchange(ref pendingSlot, 1, 0) != 0)
                    {
                        ;
                    }
                    while (active.resource.IsAcquired)
                    {
                        ;
                    }
                    ResourceProperties temp = active;
                    active   = inactive;
                    inactive = temp;
                    Interlocked.Decrement(ref pendingSlot);
                    inactive.state = ResourceState.Unloading;
                    resourceLoader.Unload(this, evt);

                    return;

                case ResourceState.Empty:
                    Interlocked.Decrement(ref pendingOperation);
                    evt.Finish();
                    return;

                case ResourceState.Loading:
                    throw new NotSupportedException("tried to unload resource while loading");

                case ResourceState.Unloading:
                    throw new NotSupportedException("tried to unload resource while unloading");

                default:
                    throw new NotSupportedException("this should never occur!");
                }

            case ResourceState.Loading:
                throw new NotSupportedException("tried to unload resource while loading");

            case ResourceState.Unloading:
                throw new NotSupportedException("tried to unload resource while unloading");

            default:
                throw new NotSupportedException("this should never occur!");
            }
        }
Exemplo n.º 3
0
        public void Unload()
        {
            if ((Interlocked.CompareExchange(ref pendingOperation, 1, 0) == 0))
            {
                switch (inactive.state)
                {
                case ResourceState.Ready:
                    if (inactive.resource.IsAcquired)
                    {
                        Interlocked.Decrement(ref pendingOperation);
                    }
                    else
                    {
                        inactive.state = ResourceState.Unloading;
                        resourceLoader.Unload(this);
                    }
                    return;

                case ResourceState.Empty:
                    switch (active.state)
                    {
                    case ResourceState.Ready:
                        bool swapped = false;
                        while (Interlocked.CompareExchange(ref pendingSlot, 1, 0) != 0)
                        {
                            ;
                        }
                        if (!active.resource.IsAcquired)
                        {
                            ResourceProperties temp = active;
                            active   = inactive;
                            inactive = temp;
                            swapped  = true;
                        }
                        Interlocked.Decrement(ref pendingSlot);
                        if (swapped)
                        {
                            inactive.state = ResourceState.Unloading;
                            resourceLoader.Unload(this);
                        }
                        else
                        {
                            Interlocked.Decrement(ref pendingOperation);
                        }
                        return;

                    case ResourceState.Empty:
                        Interlocked.Decrement(ref pendingOperation);
                        return;

                    case ResourceState.Loading:
                        throw new NotSupportedException("tried to unload resource while loading");

                    case ResourceState.Unloading:
                        throw new NotSupportedException("tried to unload resource while unloading");

                    default:
                        throw new NotSupportedException("this should never occur!");
                    }

                case ResourceState.Loading:
                    throw new NotSupportedException("tried to unload resource while loading");

                case ResourceState.Unloading:
                    throw new NotSupportedException("tried to unload resource while unloading");

                default:
                    throw new NotSupportedException("this should never occur!");
                }
            }
        }