Ejemplo n.º 1
0
        public static LightningContext Get(Accelerator accelerator)
        {
            Debug.Assert(accelerator != null, "Invalid accelerator");

            readerWriterLock.EnterUpgradeableReadLock();
            try
            {
                if (!cache.TryGetValue(accelerator, out LightningContext result))
                {
                    readerWriterLock.EnterWriteLock();
                    try
                    {
                        result = new LightningContext(accelerator);
                        accelerator.Disposed += DisposedCallback;
                        cache.Add(accelerator, result);
                    }
                    finally
                    {
                        readerWriterLock.ExitWriteLock();
                    }
                }
                return(result);
            }
            finally
            {
                readerWriterLock.ExitUpgradeableReadLock();
            }
        }
Ejemplo n.º 2
0
        public static LightningContext Get(Accelerator accelerator)
        {
            if (accelerator == null)
            {
                throw new ArgumentNullException(nameof(accelerator));
            }

            lock (cache)
            {
                if (!cache.TryGetValue(accelerator, out LightningContext result))
                {
                    result = new LightningContext(accelerator);
                    accelerator.Disposed += DisposedCallback;
                    cache.Add(accelerator, result);
                }
                return(result);
            }
        }