mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 实现了基于键的细粒度异步锁机制 - 提供自动清理未使用锁的功能,避免内存泄漏 - 集成了统计信息收集功能,便于监控和调试 - 支持同步和异步两种锁获取方式 - 实现了锁句柄的自动释放机制 - 添加了完整的单元测试覆盖各种并发场景
66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
// Copyright (c) 2025 GeWuYou
|
||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
// you may not use this file except in compliance with the License.
|
||
// You may obtain a copy of the License at
|
||
//
|
||
// http://www.apache.org/licenses/LICENSE-2.0
|
||
//
|
||
// Unless required by applicable law or agreed to in writing, software
|
||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
// See the License for the specific language governing permissions and
|
||
// limitations under the License.
|
||
|
||
namespace GFramework.Core.Abstractions.Concurrency;
|
||
|
||
/// <summary>
|
||
/// 锁统计信息
|
||
/// </summary>
|
||
public readonly struct LockStatistics
|
||
{
|
||
/// <summary>
|
||
/// 当前活跃的锁数量
|
||
/// </summary>
|
||
public int ActiveLockCount { get; init; }
|
||
|
||
/// <summary>
|
||
/// 累计获取锁的次数
|
||
/// </summary>
|
||
public int TotalAcquired { get; init; }
|
||
|
||
/// <summary>
|
||
/// 累计释放锁的次数
|
||
/// </summary>
|
||
public int TotalReleased { get; init; }
|
||
|
||
/// <summary>
|
||
/// 累计清理的锁数量
|
||
/// </summary>
|
||
public int TotalCleaned { get; init; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 锁信息(用于调试)
|
||
/// </summary>
|
||
public readonly struct LockInfo
|
||
{
|
||
/// <summary>
|
||
/// 锁的键
|
||
/// </summary>
|
||
public string Key { get; init; }
|
||
|
||
/// <summary>
|
||
/// 当前引用计数
|
||
/// </summary>
|
||
public int ReferenceCount { get; init; }
|
||
|
||
/// <summary>
|
||
/// 最后访问时间戳(Environment.TickCount64)
|
||
/// </summary>
|
||
public long LastAccessTicks { get; init; }
|
||
|
||
/// <summary>
|
||
/// 等待队列长度
|
||
/// </summary>
|
||
public int WaitingCount { get; init; }
|
||
} |