三国卡牌客户端基础资源仓库
yyl
2025-08-25 214fe94eaf7f09741a7857775dfffe8c3b83c75c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Runtime.CompilerServices;
 
namespace Cysharp.Threading.Tasks.Internal
{
    internal sealed class PooledDelegate<T> : ITaskPoolNode<PooledDelegate<T>>
    {
        static TaskPool<PooledDelegate<T>> pool;
 
        PooledDelegate<T> nextNode;
        public ref PooledDelegate<T> NextNode => ref nextNode;
 
        static PooledDelegate()
        {
            TaskPool.RegisterSizeGetter(typeof(PooledDelegate<T>), () => pool.Size);
        }
 
        readonly Action<T> runDelegate;
        Action continuation;
 
        PooledDelegate()
        {
            runDelegate = Run;
        }
 
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static Action<T> Create(Action continuation)
        {
            if (!pool.TryPop(out var item))
            {
                item = new PooledDelegate<T>();
            }
 
            item.continuation = continuation;
            return item.runDelegate;
        }
 
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void Run(T _)
        {
            var call = continuation;
            continuation = null;
            if (call != null)
            {
                pool.TryPush(this);
                call.Invoke();
            }
        }
    }
}