-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThreadPoolAdaptor.cs
62 lines (55 loc) · 1.55 KB
/
ThreadPoolAdaptor.cs
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
51
52
53
54
55
56
57
58
59
60
61
62
using System.Threading;
namespace AsyncFiberWorks.Threading
{
/// <summary>
/// Wrapper that shows IDedicatedConsumerThread as an IThreadPool.
/// </summary>
public class ThreadPoolAdaptor : IThreadWork, IDedicatedThreadPool
{
private readonly IDedicatedConsumerThreadWork _queue;
/// <summary>
/// Create an IThreadPool wrapper by the specified queue.
/// </summary>
/// <param name="queue"></param>
public ThreadPoolAdaptor(IDedicatedConsumerThreadWork queue)
{
_queue = queue;
}
/// <summary>
/// Create an IThreadPool wrapper using some IDedicatedConsumerThread.
/// </summary>
public ThreadPoolAdaptor()
: this(new BlockingCollectionQueue())
{
}
/// <summary>
/// Enqueues action.
/// </summary>
/// <param name="callback"></param>
public void Queue(WaitCallback callback)
{
_queue.Enqueue(() => callback(null));
}
/// <summary>
/// Start consumption. Continue until stopped.
/// Make the current thread available as an IThreadPool.
/// </summary>
public void Run()
{
_queue.Run();
}
/// <summary>
/// No effect. For IThreadPoolController.
/// </summary>
public void Start()
{
}
/// <summary>
/// Stop consumption.
/// </summary>
public void Stop()
{
_queue.Stop();
}
}
}