internal SparselyPopulatedArrayAddInfo(SparselyPopulatedArrayFragment <T> source, int index)
 {
     this.m_source = source;
     this.m_index  = index;
 }
Esempio n. 2
0
 internal SparselyPopulatedArrayFragment(int size, SparselyPopulatedArrayFragment <T> prev)
 {
     this.m_elements  = new T[size];
     this.m_freeCount = size;
     this.m_prev      = prev;
 }
Esempio n. 3
0
 public CancellationCallbackCoreWorkArguments(SparselyPopulatedArrayFragment <CancellationCallbackInfo> currArrayFragment, int currArrayIndex)
 {
     this.m_currArrayFragment = currArrayFragment;
     this.m_currArrayIndex    = currArrayIndex;
 }
        internal SparselyPopulatedArrayAddInfo <T> Add(T element)
        {
            int num2;

            while (true)
            {
                SparselyPopulatedArrayFragment <T> mTail = m_tail;
                while (mTail.m_next != null)
                {
                    SparselyPopulatedArrayFragment <T> mNext = mTail.m_next;
                    mTail  = mNext;
                    m_tail = mNext;
                }
                for (SparselyPopulatedArrayFragment <T> i = mTail; i != null; i = i.m_prev)
                {
                    if (i.m_freeCount < 1)
                    {
                        SparselyPopulatedArrayFragment <T> mFreeCount = i;
                        mFreeCount.m_freeCount = mFreeCount.m_freeCount - 1;
                    }
                    if (i.m_freeCount > 0 || i.m_freeCount < -10)
                    {
                        int length = i.Length;
                        int num    = (length - i.m_freeCount) % length;
                        if (num < 0)
                        {
                            num = 0;
                            SparselyPopulatedArrayFragment <T> sparselyPopulatedArrayFragment = i;
                            sparselyPopulatedArrayFragment.m_freeCount = sparselyPopulatedArrayFragment.m_freeCount - 1;
                        }
                        for (int j = 0; j < length; j++)
                        {
                            int num1 = (num + j) % length;
                            if (i.m_elements[num1] == null)
                            {
                                T t = default(T);
                                if (Interlocked.CompareExchange <T>(ref i.m_elements[num1], element, t) == null)
                                {
                                    int mFreeCount1 = i.m_freeCount - 1;
                                    SparselyPopulatedArrayFragment <T> sparselyPopulatedArrayFragment1 = i;
                                    if (mFreeCount1 > 0)
                                    {
                                        num2 = mFreeCount1;
                                    }
                                    else
                                    {
                                        num2 = 0;
                                    }
                                    sparselyPopulatedArrayFragment1.m_freeCount = num2;
                                    return(new SparselyPopulatedArrayAddInfo <T>(i, num1));
                                }
                            }
                        }
                    }
                }
                SparselyPopulatedArrayFragment <T> sparselyPopulatedArrayFragment2 = new SparselyPopulatedArrayFragment <T>(((int)mTail.m_elements.Length == 4096 ? 4096 : (int)mTail.m_elements.Length * 2), mTail);
                if (Interlocked.CompareExchange <SparselyPopulatedArrayFragment <T> >(ref mTail.m_next, sparselyPopulatedArrayFragment2, null) == null)
                {
                    m_tail = sparselyPopulatedArrayFragment2;
                }
            }
        }
        private void ExecuteCallbackHandlers(bool throwOnFirstException)
        {
            List <Exception> list = null;

            SparselyPopulatedArray <CancellationCallbackInfo>[] registeredCallbacksLists = this.m_registeredCallbacksLists;
            if (registeredCallbacksLists == null)
            {
                Interlocked.Exchange(ref this.m_state, 3);
                return;
            }
            try
            {
                foreach (SparselyPopulatedArray <CancellationCallbackInfo> sparselyPopulatedArray in registeredCallbacksLists)
                {
                    if (sparselyPopulatedArray != null)
                    {
                        for (SparselyPopulatedArrayFragment <CancellationCallbackInfo> sparselyPopulatedArrayFragment = sparselyPopulatedArray.Tail; sparselyPopulatedArrayFragment != null; sparselyPopulatedArrayFragment = sparselyPopulatedArrayFragment.Prev)
                        {
                            for (int j = sparselyPopulatedArrayFragment.Length - 1; j >= 0; j--)
                            {
                                this.m_executingCallback = sparselyPopulatedArrayFragment[j];
                                if (this.m_executingCallback != null)
                                {
                                    CancellationCallbackCoreWorkArguments cancellationCallbackCoreWorkArguments = new CancellationCallbackCoreWorkArguments(sparselyPopulatedArrayFragment, j);
                                    try
                                    {
                                        if (this.m_executingCallback.TargetSyncContext != null)
                                        {
                                            this.m_executingCallback.TargetSyncContext.Send(new SendOrPostCallback(this.CancellationCallbackCoreWork_OnSyncContext), cancellationCallbackCoreWorkArguments);
                                            this.ThreadIDExecutingCallbacks = Thread.CurrentThread.ManagedThreadId;
                                        }
                                        else
                                        {
                                            this.CancellationCallbackCoreWork_OnSyncContext(cancellationCallbackCoreWorkArguments);
                                        }
                                    }
                                    catch (Exception item)
                                    {
                                        if (throwOnFirstException)
                                        {
                                            throw;
                                        }
                                        if (list == null)
                                        {
                                            list = new List <Exception>();
                                        }
                                        list.Add(item);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                this.m_state             = 3;
                this.m_executingCallback = null;
                Thread.MemoryBarrier();
            }
            if (list != null)
            {
                throw new AggregateException(list);
            }
        }