Exemple #1
0
        internal void Untrack(TrackedLock lck)
        {
            bool temp;

            if (!Locks.TryRemove(lck, out temp))
            {
                throw new ThreadStateException();
            }

            OrderedDictionary <Wait, bool> waits;

            if (Waits.TryGet(lck, out waits))
            {
                lock (waits) {
                    foreach (var w in waits)
                    {
                        w.Key.Dispose();
                    }

                    waits.Clear();
                }

                if (!Waits.TryRemove(lck))
                {
                    throw new ThreadStateException();
                }
            }
        }
Exemple #2
0
        internal void Untrack(WeakTrackedLockReference weakLock)
        {
            var lck = (TrackedLock)weakLock.Target;

            if (lck == null)
            {
                return;
            }

            bool temp;

            if (!Locks.TryRemove(weakLock, out temp))
            {
                throw new ThreadStateException();
            }

            OrderedDictionary <Wait, bool> waits;

            if (Waits.TryGet(lck, out waits))
            {
                lock (waits) {
                    foreach (var w in waits)
                    {
                        w.Key.Dispose();
                    }

                    waits.Clear();
                }

                if (!Waits.TryRemove(lck))
                {
                    throw new ThreadStateException();
                }
            }
        }
Exemple #3
0
        public TypeInfo GetTypeInformation(TypeReference type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            TypeInfo result;
            var      typedef = TypeUtil.GetTypeDefinition(type);

            if (typedef == null)
            {
                return(null);
            }

            var identifier = new TypeIdentifier(typedef);

            if (TypeInformation.TryGet(identifier, out result))
            {
                return(result);
            }

            var args = new MakeTypeInfoArgs();

            EnqueueType(args.TypesToInitialize, type);

            // We must construct type information in two passes, so that method group construction
            //  behaves correctly and ignores all the right methods.
            // The first pass walks all the way through the type graph (starting with the current type),
            //  ensuring we have type information for all the types in the graph. We do this iteratively
            //  to avoid overflowing the stack.
            // After we have type information for all the types in the graph, we then walk over all
            //  the types again, and construct their method groups, since we have the necessary
            //  information to determine which methods are ignored.
            while (args.TypesToInitialize.Count > 0)
            {
                var kvp = args.TypesToInitialize.First;
                args.TypesToInitialize.Remove(kvp.Key);

                args.Definition = kvp.Value;
                TypeInformation.TryCreate(
                    kvp.Key, args, MakeTypeInfo
                    );
            }

            foreach (var ti in args.SecondPass.Values)
            {
                ti.Initialize();
                ti.ConstructMethodGroups();
            }

            if (!TypeInformation.TryGet(identifier, out result))
            {
                return(null);
            }
            else
            {
                return(result);
            }
        }
Exemple #4
0
        public bool TryGetExpression(QualifiedMemberIdentifier method, out JSFunctionExpression function)
        {
            Entry entry;

            if (!Cache.TryGet(method, out entry))
            {
                function = null;
                return(false);
            }

            function = entry.Expression;
            return(true);
        }
Exemple #5
0
        public void AssignIdentifiers()
        {
            lock (_syncRoot)
            {
                if (AssignedIdentifiers)
                {
                    return;
                }

                var names = (from kvp in Tokens select kvp.Key).OrderBy((k) => k);
                int max   = (from kvp in Tokens select kvp.Value.ID.GetValueOrDefault(-1)).Max();

                int i = max + 1;

                foreach (var name in names)
                {
                    Token token;
                    if (Tokens.TryGet(name, out token))
                    {
                        if (!token.ID.HasValue)
                        {
                            token.ID = i++;
                        }
                    }
                }

                AssignedIdentifiers = true;
            }
        }
Exemple #6
0
        bool ITypeInfoSource.TryGetProxyNames(TypeReference tr, out ArraySegment <string> result)
        {
            result = ImmutableArrayPool <string> .Empty;

            ProxiesByNameRecord proxiesByFullName;
            var name = new HashedString(tr.Name);

            if (!ProxiesByName.TryGet(name, out proxiesByFullName))
            {
                return(false);
            }

            if (proxiesByFullName.Count == 0)
            {
                return(false);
            }

            var fullName = new HashedString(tr.FullName);

            return(proxiesByFullName.Cache.TryGet(fullName, out result));
        }
Exemple #7
0
        bool ITypeInfoSource.TryGetProxyNames(TypeReference tr, out string[] result)
        {
            result = null;

            ProxiesByNameRecord proxiesByFullName;
            var name = new HashedString(tr.Name);

            if (!ProxiesByName.TryGet(name, out proxiesByFullName))
            {
                return(false);
            }

            if (proxiesByFullName.Count == 0)
            {
                return(false);
            }

            var fullName = new HashedString(tr.FullName);

            return(proxiesByFullName.Cache.TryGet(fullName, out result));
        }
Exemple #8
0
 bool ITypeInfoSource.TryGetProxyNames(string typeFullName, out string[] result)
 {
     return(ProxiesByName.TryGet(typeFullName, out result));
 }
Exemple #9
0
        public TypeInfo GetTypeInformation(TypeReference type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            TypeInfo result;
            var      identifier = new TypeIdentifier(type);

            if (TypeInformation.TryGet(identifier, out result))
            {
                return(result);
            }

            var fullName = type.FullName;

            var moreTypes         = new Dictionary <TypeIdentifier, TypeDefinition>();
            var typesToInitialize = new OrderedDictionary <TypeIdentifier, TypeDefinition>();
            var secondPass        = new Dictionary <TypeIdentifier, TypeInfo>();

            EnqueueType(typesToInitialize, type);

            // We must construct type information in two passes, so that method group construction
            //  behaves correctly and ignores all the right methods.
            // The first pass walks all the way through the type graph (starting with the current type),
            //  ensuring we have type information for all the types in the graph. We do this iteratively
            //  to avoid overflowing the stack.
            // After we have type information for all the types in the graph, we then walk over all
            //  the types again, and construct their method groups, since we have the necessary
            //  information to determine which methods are ignored.
            while (typesToInitialize.Count > 0)
            {
                var kvp = typesToInitialize.First;
                typesToInitialize.Remove(kvp.Key);

                TypeInformation.TryCreate(
                    kvp.Key, () => {
                    var constructed = ConstructTypeInformation(kvp.Key, kvp.Value, moreTypes);
                    secondPass.Add(kvp.Key, constructed);

                    foreach (var more in moreTypes)
                    {
                        EnqueueType(typesToInitialize, more.Value);
                    }
                    moreTypes.Clear();

                    return(constructed);
                }
                    );
            }

            foreach (var ti in secondPass.Values)
            {
                ti.Initialize();
                ti.ConstructMethodGroups();
            }

            if (!TypeInformation.TryGet(identifier, out result))
            {
                return(null);
            }
            else
            {
                return(result);
            }
        }