mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-11 13:56:33 -06:00
As VS 2022 doesn't seem to store files with UTF-8 BOM as often anymore, we've been getting more and more pull requests which seemingly randomly change files. This cleans the situation up by removing the BOM from all files that have one. Additionally, `Host.Tests.Feature.rc` was converted from UTF-16 to UTF-8.
59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Samples.Terminal
|
|
{
|
|
/// <summary>
|
|
/// Implements a bounded queue that won't block on overflow; instead the oldest item is discarded.
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public class ConcurrentBoundedQueue<T> : ConcurrentQueue<T>
|
|
{
|
|
public ConcurrentBoundedQueue(int capacity)
|
|
{
|
|
Capacity = GetAlignedCapacity(capacity);
|
|
}
|
|
|
|
public ConcurrentBoundedQueue(IEnumerable<T> collection, int capacity) : base(collection)
|
|
{
|
|
Capacity = GetAlignedCapacity(capacity);
|
|
}
|
|
|
|
private int GetAlignedCapacity(int n)
|
|
{
|
|
if (n < 2)
|
|
{
|
|
throw new ArgumentException("Capacity must be at least 2");
|
|
}
|
|
|
|
var f = Math.Log(n, 2);
|
|
var p = Math.Ceiling(f);
|
|
|
|
return (int) Math.Pow(2, p);
|
|
}
|
|
|
|
public new void Enqueue(T item)
|
|
{
|
|
// if we're about to overflow, dump oldest item
|
|
if (Count >= Capacity)
|
|
{
|
|
lock (this)
|
|
{
|
|
while (Count >= Capacity)
|
|
{
|
|
TryDequeue(out _);
|
|
}
|
|
}
|
|
}
|
|
|
|
base.Enqueue(item);
|
|
}
|
|
|
|
public int Capacity
|
|
{
|
|
get; private set;
|
|
}
|
|
}
|
|
}
|