mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-19 01:31:17 -10:00
Adding reference source for System.Data System.Data.DataSetExtensions System.Data.Entity System.Data.Entity.Design System.Data.Linq System.Data.SqlXml System.ServiceModel System.ServiceModel.Activation System.ServiceModel.Activities System.ServiceModel.Channels System.ServiceModel.Discovery System.ServiceModel.Internals System.ServiceModel.Routing System.ServiceModel.WasHosting System.ServiceModel.Web System.Web System.Web.ApplicationServices System.Web.DynamicData System.Web.Entity System.Web.Entity.Design System.Web.Extensions System.Web.Mobile System.Web.Routing System.Web.Services System.Xml System.Xml.Linq
55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
//------------------------------------------------------------------------------
|
|
// <copyright file="CountdownTask.cs" company="Microsoft">
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// </copyright>
|
|
//------------------------------------------------------------------------------
|
|
|
|
namespace System.Web.Util {
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
// This class is similar to CountdownEvent, but it uses Task under the covers
|
|
// instead of ManualResetEvent. When the internal counter hits zero, the Task
|
|
// is marked as complete.
|
|
//
|
|
// This type is thread-safe. Error checking is not performed in RET builds.
|
|
|
|
internal sealed class CountdownTask {
|
|
|
|
private int _pendingCount;
|
|
private readonly TaskCompletionSource<object> _tcs = new TaskCompletionSource<object>();
|
|
|
|
public CountdownTask(int initialCount) {
|
|
AddCount(initialCount);
|
|
}
|
|
|
|
public int CurrentCount {
|
|
get { return _pendingCount; }
|
|
}
|
|
|
|
public Task Task {
|
|
get { return _tcs.Task; }
|
|
}
|
|
|
|
private void AddCount(int delta) {
|
|
int newCount = Interlocked.Add(ref _pendingCount, delta);
|
|
Debug.Assert(newCount >= 0, "The counter should never hit a negative value.");
|
|
|
|
if (newCount == 0) {
|
|
bool success = _tcs.TrySetResult(null);
|
|
Debug.Assert(success, "TrySetResult shouldn't have been already called.");
|
|
}
|
|
}
|
|
|
|
public void MarkOperationCompleted() {
|
|
AddCount(-1);
|
|
}
|
|
|
|
public void MarkOperationPending() {
|
|
AddCount(+1);
|
|
}
|
|
|
|
}
|
|
}
|