diff options
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/Native/BatchableExtensions.cs')
-rw-r--r-- | Xamarin.Forms.Platform.Tizen/Native/BatchableExtensions.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Native/BatchableExtensions.cs b/Xamarin.Forms.Platform.Tizen/Native/BatchableExtensions.cs new file mode 100644 index 00000000..5f630e1b --- /dev/null +++ b/Xamarin.Forms.Platform.Tizen/Native/BatchableExtensions.cs @@ -0,0 +1,64 @@ +using System.Runtime.CompilerServices; + +namespace Xamarin.Forms.Platform.Tizen.Native +{ + internal static class BatchableExtensions + { + static readonly ConditionalWeakTable<IBatchable, BatchCount> s_counters = new ConditionalWeakTable<IBatchable, BatchCount>(); + + public static void BatchBegin(this IBatchable target) + { + BatchCount value = null; + + if (s_counters.TryGetValue(target, out value)) + { + value.Count++; + } + else + { + s_counters.Add(target, new BatchCount()); + } + } + + public static void BatchCommit(this IBatchable target) + { + BatchCount value = null; + if (s_counters.TryGetValue(target, out value)) + { + value.Count--; + if (value.Count == 0) + { + target.OnBatchCommitted(); + } + else if (value.Count < 0) + { + Log.Error("Called BatchCommit() without BatchBegin()."); + value.Count = 0; + } + } + else + { + Log.Error("Called BatchCommit() without BatchBegin()."); + } + } + + public static bool IsBatched(this IBatchable target) + { + BatchCount value = null; + + if (s_counters.TryGetValue(target, out value)) + { + return value.Count != 0; + } + else + { + return false; + } + } + + class BatchCount + { + public int Count = 1; + } + } +} |