-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from serilog/dev
2.1.0 Release
- Loading branch information
Showing
23 changed files
with
907 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,3 +234,5 @@ _Pvt_Extensions | |
|
||
# FAKE - F# Make | ||
.fake/ | ||
|
||
BenchmarkDotNet.Artifacts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Push-Location $PSScriptRoot | ||
|
||
./Build.ps1 | ||
|
||
foreach ($test in ls test/*.PerformanceTests) { | ||
Push-Location $test | ||
|
||
echo "perf: Running performance test project in $test" | ||
|
||
& dotnet test -c Release | ||
if($LASTEXITCODE -ne 0) { exit 2 } | ||
|
||
Pop-Location | ||
} | ||
|
||
Pop-Location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/BoundedConcurrentQueue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Threading; | ||
|
||
namespace Serilog.Sinks.PeriodicBatching | ||
{ | ||
class BoundedConcurrentQueue<T> | ||
{ | ||
const int NON_BOUNDED = -1; | ||
|
||
readonly ConcurrentQueue<T> _queue = new ConcurrentQueue<T>(); | ||
readonly int _queueLimit; | ||
|
||
int _counter; | ||
|
||
public BoundedConcurrentQueue() | ||
{ | ||
_queueLimit = NON_BOUNDED; | ||
} | ||
|
||
public BoundedConcurrentQueue(int queueLimit) | ||
{ | ||
if (queueLimit <= 0) | ||
throw new ArgumentOutOfRangeException(nameof(queueLimit), "queue limit must be positive"); | ||
|
||
_queueLimit = queueLimit; | ||
} | ||
|
||
public int Count => _queue.Count; | ||
|
||
public bool TryDequeue(out T item) | ||
{ | ||
if (_queueLimit == NON_BOUNDED) | ||
return _queue.TryDequeue(out item); | ||
|
||
var result = false; | ||
try | ||
{ } | ||
finally // prevent state corrupt while aborting | ||
{ | ||
if (_queue.TryDequeue(out item)) | ||
{ | ||
Interlocked.Decrement(ref _counter); | ||
result = true; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public bool TryEnqueue(T item) | ||
{ | ||
if (_queueLimit == NON_BOUNDED) | ||
{ | ||
_queue.Enqueue(item); | ||
return true; | ||
} | ||
|
||
var result = true; | ||
try | ||
{ } | ||
finally | ||
{ | ||
if (Interlocked.Increment(ref _counter) <= _queueLimit) | ||
{ | ||
_queue.Enqueue(item); | ||
} | ||
else | ||
{ | ||
Interlocked.Decrement(ref _counter); | ||
result = false; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.