From d15a376e0b7436668d221a70527f7a2f12559164 Mon Sep 17 00:00:00 2001 From: Lluis Sanchez Date: Thu, 16 Jun 2022 13:17:30 +0200 Subject: Add some docs and fix formatting --- Mono.Addins/Mono.Addins.Database/AddinHostIndex.cs | 8 ++++---- Mono.Addins/Mono.Addins/ExtensionContext.cs | 23 ++++++++++----------- .../Mono.Addins/ExtensionContextTransaction.cs | 24 +++++++++++++++++----- Mono.Addins/Mono.Addins/ExtensionNodeList.cs | 4 ++-- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Mono.Addins/Mono.Addins.Database/AddinHostIndex.cs b/Mono.Addins/Mono.Addins.Database/AddinHostIndex.cs index 713384a..571deda 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinHostIndex.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinHostIndex.cs @@ -137,7 +137,7 @@ namespace Mono.Addins.Database { Dictionary index; - public ImmutableAddinHostIndex (): this(new Dictionary()) + public ImmutableAddinHostIndex () : this (new Dictionary ()) { } @@ -151,9 +151,9 @@ namespace Mono.Addins.Database return AddinHostIndex.LookupAddinForAssembly (index, assemblyLocation, out addinId, out addinLocation, out domain); } - public Dictionary ToDictionary () - { + public Dictionary ToDictionary () + { return new Dictionary (index); } - } + } } diff --git a/Mono.Addins/Mono.Addins/ExtensionContext.cs b/Mono.Addins/Mono.Addins/ExtensionContext.cs index b3205b9..5e719d4 100644 --- a/Mono.Addins/Mono.Addins/ExtensionContext.cs +++ b/Mono.Addins/Mono.Addins/ExtensionContext.cs @@ -31,24 +31,23 @@ using System; using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; -using System.Collections.Specialized; using System.Linq; using System.Threading; using Mono.Addins.Description; namespace Mono.Addins { - /// - /// An extension context. - /// - /// - /// Extension contexts can be used to query the extension tree - /// using particular condition values. Extension points which - /// declare the availability of a condition type can only be - /// queryed using an extension context which provides an - /// evaluator for that condition. - /// - public class ExtensionContext + /// + /// An extension context. + /// + /// + /// Extension contexts can be used to query the extension tree + /// using particular condition values. Extension points which + /// declare the availability of a condition type can only be + /// queryed using an extension context which provides an + /// evaluator for that condition. + /// + public class ExtensionContext { internal object LocalLock = new object (); diff --git a/Mono.Addins/Mono.Addins/ExtensionContextTransaction.cs b/Mono.Addins/Mono.Addins/ExtensionContextTransaction.cs index 3507f49..18d0eb3 100644 --- a/Mono.Addins/Mono.Addins/ExtensionContextTransaction.cs +++ b/Mono.Addins/Mono.Addins/ExtensionContextTransaction.cs @@ -33,8 +33,20 @@ using System.Threading; namespace Mono.Addins { - class ExtensionContextTransaction : IDisposable - { + /// + /// Represents a mutation action of an extension context. It is necessary to acquire a transaction object + /// when doing changes in a context (methods that modify a context take a transaction as parameter). + /// Getting a transaction is a blocking operation: if a thread has started a transaction, other threads trying + /// to get one will be blocked until the current transaction is finished. + /// The transaction objects collects two kind of information: + /// 1) changes to be done in the context. For example, it collects conditions to be registered, and then all conditions + /// are added to the context at once when the transaction is completed (so the immutable collection that holds + /// the condition list can be updated with a single allocation). + /// 2) events to be fired once the transaction is completed. This is to avoid firing events while the context + /// lock is taken. + /// + class ExtensionContextTransaction : IDisposable + { List loadedNodes; HashSet childrenChanged; HashSet extensionsChanged; @@ -59,8 +71,10 @@ namespace Mono.Addins public bool DisableEvents { get; set; } public void Dispose () - { + { try { + // Update the context + if (nodeConditions != null) { Context.BulkRegisterNodeConditions (this, nodeConditions); } @@ -93,7 +107,7 @@ namespace Mono.Addins } if (extensionsChanged != null) { foreach (var path in extensionsChanged) - Context.NotifyExtensionsChanged(new ExtensionEventArgs(path)); + Context.NotifyExtensionsChanged (new ExtensionEventArgs (path)); } if (registeredAutoExtensionPoints != null) { var engine = (AddinEngine)Context; @@ -113,7 +127,7 @@ namespace Mono.Addins } if (addinLoadEvents != null) { var engine = (AddinEngine)Context; - foreach(var addin in addinLoadEvents) + foreach (var addin in addinLoadEvents) engine.ReportAddinLoad (addin); } if (addinUnloadEvents != null) { diff --git a/Mono.Addins/Mono.Addins/ExtensionNodeList.cs b/Mono.Addins/Mono.Addins/ExtensionNodeList.cs index b2a6586..fc90fc8 100644 --- a/Mono.Addins/Mono.Addins/ExtensionNodeList.cs +++ b/Mono.Addins/Mono.Addins/ExtensionNodeList.cs @@ -103,8 +103,8 @@ namespace Mono.Addins list.CopyTo (array, index); } - IEnumerator IEnumerable.GetEnumerator () - { + IEnumerator IEnumerable.GetEnumerator () + { return list.GetEnumerator (); } } -- cgit v1.2.3