You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/Logging/FixSizeLogMessageBuffer.cs

46 lines
1.2 KiB

6 years ago
using System;
using System.Threading;
using ZeroLevel.Services.Collections;
namespace ZeroLevel.Services.Logging
{
internal sealed class FixSizeLogMessageBuffer
6 years ago
: ILogMessageBuffer
{
private readonly FixSizeQueue<Tuple<LogLevel, string>> _queue;
private readonly ManualResetEvent _waitItemsFlag = new ManualResetEvent(false);
public FixSizeLogMessageBuffer(long backlog)
{
_queue = new FixSizeQueue<Tuple<LogLevel, string>>(backlog);
}
public long Count
{
get
{
return _queue.Count;
}
}
public void Dispose()
{
_waitItemsFlag.Dispose();
}
public void Push(LogLevel level, string message)
{
_queue.Push(new Tuple<LogLevel, string>(level, message));
_waitItemsFlag.Set();
}
public Tuple<LogLevel, string> Take()
{
while (_queue.Count == 0)
_waitItemsFlag.WaitOne(110);
var t = _queue.Take();
if (_queue.Count == 0) _waitItemsFlag.Reset();
return t;
}
}
}

Powered by TurnKey Linux.