IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IKVM.Tools.Core.Diagnostics.AsyncDiagnosticChannelWriter Class Reference

Wraps a IBufferWriter<T> and queues data writen to it. Requires disposal to ensure flushing. More...

Inheritance diagram for IKVM.Tools.Core.Diagnostics.AsyncDiagnosticChannelWriter:
IKVM.Tools.Core.Diagnostics.IDiagnosticChannelWriter

Public Member Functions

 AsyncDiagnosticChannelWriter (IBufferWriter< byte > writer)
 Initializes a new instance.
 
void Write (IMemoryOwner< byte > owner, int length)
 Enqueues the given memory to be written. Ownership is transfered.
 
void Dispose ()
 Disposes of the instance.
 
- Public Member Functions inherited from IKVM.Tools.Core.Diagnostics.IDiagnosticChannelWriter

Detailed Description

Wraps a IBufferWriter<T> and queues data writen to it. Requires disposal to ensure flushing.

Definition at line 13 of file AsyncDiagnosticChannelWriter.cs.

Constructor & Destructor Documentation

◆ AsyncDiagnosticChannelWriter()

IKVM.Tools.Core.Diagnostics.AsyncDiagnosticChannelWriter.AsyncDiagnosticChannelWriter ( IBufferWriter< byte > writer)

Initializes a new instance.

Parameters
writer
Exceptions
ArgumentNullException

Definition at line 34 of file AsyncDiagnosticChannelWriter.cs.

35 {
36 _writer = writer ?? throw new ArgumentNullException(nameof(writer));
37 }

Member Function Documentation

◆ Dispose()

void IKVM.Tools.Core.Diagnostics.AsyncDiagnosticChannelWriter.Dispose ( )

Disposes of the instance.

Definition at line 102 of file AsyncDiagnosticChannelWriter.cs.

103 {
104 lock (this)
105 {
106 // stop dequeue task
107 _stop?.Cancel();
108 _task?.GetAwaiter().GetResult();
109 _stop = null;
110 _task = null;
111
112 // empty the channel to pick up any straggling items not caught by the dequeue thread
113 while (_channel.Reader.TryRead(out var item))
114 item.Owner.Dispose();
115
116 // complete the channel
117 _channel.Writer.TryComplete();
118 }
119 }

◆ Write()

void IKVM.Tools.Core.Diagnostics.AsyncDiagnosticChannelWriter.Write ( IMemoryOwner< byte > owner,
int length )

Enqueues the given memory to be written. Ownership is transfered.

Parameters
owner

Implements IKVM.Tools.Core.Diagnostics.IDiagnosticChannelWriter.

Definition at line 43 of file AsyncDiagnosticChannelWriter.cs.

44 {
45 if (owner is null)
46 throw new ArgumentNullException(nameof(owner));
47
48 if (_stop == null || _task == null)
49 {
50 lock (this)
51 {
52 if (_stop == null || _task == null)
53 {
54 _stop = new CancellationTokenSource();
55 _task = DequeueLoop(_stop.Token);
56 }
57 }
58 }
59
60 _channel.Writer.TryWrite((owner, length));
61 }

The documentation for this class was generated from the following file: