-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid buffer race conditions in CGroups (#5129)
* Correct tests decorations * Avoid buffer race conditions in CGroups Fixes #5114
- Loading branch information
Showing
8 changed files
with
314 additions
and
180 deletions.
There are no files selected for viewing
158 changes: 78 additions & 80 deletions
158
...crosoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationParserCgroupV1.cs
Large diffs are not rendered by default.
Oops, something went wrong.
178 changes: 90 additions & 88 deletions
178
...crosoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationParserCgroupV2.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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,45 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using Microsoft.Extensions.ObjectPool; | ||
|
||
#pragma warning disable CA1716 | ||
namespace Microsoft.Shared.Pools; | ||
#pragma warning restore CA1716 | ||
|
||
/// <summary> | ||
/// Represents a buffer writer that can be automatically returned to an object pool upon dispose. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the elements in the buffer.</typeparam> | ||
#if !SHARED_PROJECT | ||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] | ||
#endif | ||
internal readonly struct ReturnableBufferWriter<T> : IDisposable | ||
{ | ||
private readonly ObjectPool<BufferWriter<T>> _pool; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ReturnableBufferWriter{T}"/> struct. | ||
/// </summary> | ||
/// <param name="pool">The object pool to return the buffer writer to.</param> | ||
public ReturnableBufferWriter(ObjectPool<BufferWriter<T>> pool) | ||
{ | ||
_pool = pool; | ||
Buffer = pool.Get(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the buffer writer. | ||
/// </summary> | ||
public BufferWriter<T> Buffer { get; } | ||
|
||
/// <summary> | ||
/// Disposes the buffer writer and returns it to the object pool. | ||
/// </summary> | ||
public readonly void Dispose() | ||
{ | ||
Buffer.Reset(); | ||
_pool.Return(Buffer); | ||
} | ||
} |
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
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
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