예제 #1
0
 private void TryCreateTeardown(TKey key, ConstructionState state)
 {
     if (States.TryRemove(key, out state))
     {
         state.Set();
         state.Dispose();
     }
 }
예제 #2
0
파일: Util.cs 프로젝트: shreedharcva/JSIL
        public bool TryCreate(TKey key, Func <TValue> creator)
        {
            ConstructionState state;

            if (Storage.ContainsKey(key))
            {
                return(false);
            }

            state = new ConstructionState();
            if (States.TryAdd(key, state))
            {
                try {
                    if (Storage.ContainsKey(key))
                    {
                        return(false);
                    }

                    var result = creator();

                    if (!Storage.TryAdd(key, result))
                    {
                        throw new InvalidOperationException("Cache entry was created by someone else while construction lock was held");
                    }

                    return(true);
                } finally {
                    States.TryRemove(key, out state);
                    state.Set();
                    state.Dispose();
                }
            }
            else
            {
                state.Dispose();
            }

            return(false);
        }