/// <summary> /// Initializes a new instance of the <see cref="ReentrantSemaphore"/> class. /// </summary> /// <param name="initialCount">The initial number of concurrent operations to allow.</param> /// <param name="joinableTaskContext">The <see cref="JoinableTaskContext"/> to use to mitigate deadlocks.</param> /// <param name="mode">How to respond to a semaphore request by a caller that has already entered the semaphore.</param> public static ReentrantSemaphore Create(int initialCount = 1, JoinableTaskContext joinableTaskContext = default, ReentrancyMode mode = ReentrancyMode.NotAllowed) { switch (mode) { case ReentrancyMode.NotRecognized: return(new NotRecognizedSemaphore(initialCount, joinableTaskContext)); case ReentrancyMode.NotAllowed: return(new NotAllowedSemaphore(initialCount, joinableTaskContext)); case ReentrancyMode.Stack: return(new StackSemaphore(initialCount, joinableTaskContext)); case ReentrancyMode.Freeform: return(new FreeformSemaphore(initialCount, joinableTaskContext)); default: throw new ArgumentOutOfRangeException(nameof(mode)); } }
/// <summary> /// Initializes a new instance of the <see cref="JoinableTaskCollection"/> class. /// </summary> /// <param name="context">The <see cref="JoinableTaskContext"/> instance to which this collection applies.</param> /// <param name="refCountAddedJobs"> /// <c>true</c> if JoinableTask instances added to the collection multiple times should remain in the collection until they are /// either removed the same number of times or until they are completed; /// <c>false</c> causes the first Remove call for a JoinableTask to remove it from this collection regardless /// how many times it had been added.</param> public JoinableTaskCollection(JoinableTaskContext context, bool refCountAddedJobs = false) { Requires.NotNull(context, nameof(context)); this.Context = context; this.refCountAddedJobs = refCountAddedJobs; }
/// <summary> /// Initializes a new instance of the <see cref="FreeformSemaphore"/> class. /// </summary> /// <param name="initialCount">The initial number of concurrent operations to allow.</param> /// <param name="joinableTaskContext">The <see cref="JoinableTaskContext"/> to use to mitigate deadlocks.</param> internal FreeformSemaphore(int initialCount, JoinableTaskContext joinableTaskContext) : base(initialCount, joinableTaskContext) { }
/// <summary> /// Initializes a new instance of the <see cref="StackSemaphore"/> class. /// </summary> /// <param name="initialCount">The initial number of concurrent operations to allow.</param> /// <param name="joinableTaskContext">The <see cref="JoinableTaskContext"/> to use to mitigate deadlocks.</param> internal StackSemaphore(int initialCount, JoinableTaskContext joinableTaskContext) : base(initialCount, joinableTaskContext) { }
/// <summary> /// Initializes a new instance of the <see cref="ReentrantSemaphore"/> class. /// </summary> /// <param name="initialCount">The initial number of concurrent operations to allow.</param> /// <param name="joinableTaskContext">The <see cref="JoinableTaskContext"/> to use to mitigate deadlocks.</param> /// <devremarks> /// This is private protected so that others cannot derive from this type but we can within the assembly. /// </devremarks> private protected ReentrantSemaphore(int initialCount, JoinableTaskContext joinableTaskContext) { this.joinableTaskCollection = joinableTaskContext?.CreateCollection(); this.joinableTaskFactory = joinableTaskContext?.CreateFactory(this.joinableTaskCollection); this.semaphore = new AsyncSemaphore(initialCount); }
/// <summary> /// Initializes a new instance of the <see cref="NotAllowedSemaphore"/> class. /// </summary> /// <param name="initialCount">The initial number of concurrent operations to allow.</param> /// <param name="joinableTaskContext">The <see cref="JoinableTaskContext"/> to use to mitigate deadlocks.</param> internal NotAllowedSemaphore(int initialCount, JoinableTaskContext joinableTaskContext) : base(initialCount, joinableTaskContext) { }
/// <summary> /// Initializes a new instance of the <see cref="NotRecognizedSemaphore"/> class. /// </summary> /// <param name="initialCount">The initial number of concurrent operations to allow.</param> /// <param name="joinableTaskContext">The <see cref="JoinableTaskContext"/> to use to mitigate deadlocks.</param> internal NotRecognizedSemaphore(int initialCount, JoinableTaskContext joinableTaskContext) : base(initialCount, joinableTaskContext) { }
/// <summary> /// Initializes a new instance of the <see cref="JoinableTaskContextNode"/> class. /// </summary> /// <param name="context">The inner JoinableTaskContext.</param> public JoinableTaskContextNode(JoinableTaskContext context) { Requires.NotNull(context, nameof(context)); this.context = context; }