private void AddMethod(MethodBase _method) { var _neptuneMethodIndex = NeptuneMethodIndexUninitialized; WeaverBase.GetNeptuneMethodIndex(_method, ref _neptuneMethodIndex); if (_neptuneMethodIndex != NeptuneMethodIndexMissing) { Methods[_neptuneMethodIndex] = _method; } }
/// <summary> /// Not thread safe /// </summary> static public void Add(WeaverBase weaver) { if (m_Adding) { // might break order of weaving, but probably otherwise safe throw new NotImplementedException("Weaving aspects on closed generics can not be done recursively"); } m_Adding = true; m_ReadWriteLock.EnterUpgradeableReadLock(); try { int _index = 0; for (; _index < m_ConstructedGenerics.Count; _index++) { var _constructedGeneric = m_ConstructedGenerics[_index]; _constructedGeneric.Weave(weaver); } //m_ReadWriteLock.EnterWriteLock(); m_ReadWriteLock.EnterWriteLock(); try { for (; _index < m_ConstructedGenerics.Count; _index++) { var _constructedGeneric = m_ConstructedGenerics[_index]; _constructedGeneric.Weave(weaver); } Extend(ref m_ClosedWeavers, weaver); } finally { m_ReadWriteLock.ExitWriteLock(); } } finally { m_ReadWriteLock.EnterUpgradeableReadLock(); m_Adding = false; } }
public override void Weave(WeaverBase weaver) { weaver.WeaveConstructedGenericType(this); }
public override void Weave(WeaverBase weaver) { weaver.WeaveConstructedGenericMethod(m_method, m_neptuneMethodIndex); }
public override void Weave(WeaverBase weaver) { weaver.WeaveMethodInConstructedType(m_method, m_neptuneMethodIndex); }
public abstract void Weave(WeaverBase weaver);
public StopwatchLog(WeaverBase weaver, string text) { this.weaver = weaver; this.stopwatch = Stopwatch.StartNew(); this.text = text; }
public void Initialize() { lock (m_Handle) { if (!NeedInitialization) { return; } WeaverBase.GetNeptuneMethodIndex(this.Method, ref m_neptuneMethodIndex); if (Type.IsGenericTypeDefinition) { // do the remaining outside the lock NeedInitialization = false; goto FinalizeGenericTypeDefinition; } else { if (Method.IsGenericMethodDefinition) { if (Type.IsGenericType) { AddToDefinition(GenericWeavers.GetTypeDefinitionItem(Type.GetGenericTypeDefinition())); } } else { if (Method.IsGenericMethod) { AddToDefinition(GenericWeavers.GetTypeItem(Type)); } else { AddToDefinition(GenericWeavers.GetTypeDefinitionItem(Type.GetGenericTypeDefinition())); } } // do the remaining outside the lock } NeedInitialization = false; } // since we are outside the lock a competing thread may have done any of the following but none of it // should have problem with that, but they all may take lock on parent and we cannot allow that while child locked // due to risk od dead lock (we should always lock parent before child to avoid dead lock) if (this.GenericDefinition != null) { if (this.GenericDefinition.NeedInitialization) { this.GenericDefinition.Initialize(); } GenericDefinition.InstantiateChild(this); } if (Method.IsGenericMethodDefinition) { foreach (var _method in GenericWeavers.GetGenericMethodDefinitionItem(Method).ConstructedMethods) { // just need to create the entry it will add it self to this.GenericInstances Obtain(_method, m_neptuneMethodIndex); } } return; FinalizeGenericTypeDefinition: foreach (var _typeItem in GenericWeavers.GetTypeDefinitionItem(Type).ConstructedTypes.Values) { // todo Jens write a unittest that verify the claim below // we could do it now but then we might trigger type loading earlier than if not used // also the side effect unit tests assume it happens on first invoke if (_typeItem.InvokedMethods[m_neptuneMethodIndex]) { // just need to create the entry it will add it self to this.GenericInstances Obtain(_typeItem.Methods[m_neptuneMethodIndex]); } } return; }