Example #1
0
        int EnsureTypeIndex(PhpTypeInfo info)
        {
            if (info.Index == 0)
            {
                TypesAppContext.RwLock.EnterWriteLock();
                try
                {
                    // double checked lock
                    if (info.Index == 0)
                    {
                        int index;
                        var name = info.Name;
                        if (_nameToIndex.TryGetValue(name, out index))
                        {
                            if (index < 0)  // redeclaring over an app context type
                            {
                                _redeclarationCallback(info);
                            }

                            info.Index = index;
                        }
                        else
                        {
                            index = _contextTypesCounter.GetNewIndex() + 1;
                            _nameToIndex[name] = index;
                        }

                        info.Index = index;
                    }
                }
                finally
                {
                    TypesAppContext.RwLock.ExitWriteLock();
                }
            }

            Debug.Assert(info.Index != 0);

            return(info.Index);
        }
Example #2
0
        int EnsureTypeIndex(PhpTypeInfo info)
        {
            if (info.Index == 0)
            {
                s_rwLock.EnterWriteLock();
                try
                {
                    // double checked lock
                    if (info.Index == 0)
                    {
                        if (s_nameToIndex.TryGetValue(info.Name, out var index))
                        {
                            if (index < 0)  // redeclaring over an app context type
                            {
                                RedeclarationError(info);
                            }

                            info.Index = index;
                        }
                        else
                        {
                            index = s_contextTypesCounter.GetNewIndex();
                            s_nameToIndex[info.Name] = index;
                        }

                        info.Index = index;
                    }
                }
                finally
                {
                    s_rwLock.ExitWriteLock();
                }
            }

            Debug.Assert(info.Index != 0);

            return(info.Index);
        }
Example #3
0
        public void DeclareType <T>()
        {
            // TODO: W lock

            var info  = TypeInfoHolder <T> .TypeInfo;
            var index = info.Index;

            if (index == 0)
            {
                var name = info.Name;
                if (_nameToIndex.TryGetValue(name, out index))
                {
                    if (index < 0)  // redeclaring over an app context type
                    {
                        _redeclarationCallback(info);
                    }

                    info.Index = index;
                }
                else
                {
                    index = _contextTypesCounter.GetNewIndex() + 1;
                    _nameToIndex[name] = index;
                }

                info.Index = index;
            }

            Debug.Assert(info.Index > 0);

            //
            if (_contextTypes.Length < index)
            {
                Array.Resize(ref _contextTypes, index * 2);
            }

            DeclareType(ref _contextTypes[index - 1], info);
        }