Struct DispatchQueue
Double buffered thread-safe queue
Limited by a maximum size that is passed in the constructor. This is an important for performance, to avoid memory reallocation during the work.
- One buffer is used for write: several threads can add new Log
Message 's to it, no one can read from that buffer. That is done via Enqueue(PayloadHandle, long, Log method that does that under the read lock[1].Level) - Second buffer is used as a read-only buffer: several sinks can read from it, without modifying anything. This is done via Begin
Read() and EndRead() that enters/exits the read lock[1]. - Second buffer also can be in an exclusive mode: Cleanup system calls Begin
Read to enter the exclusive lock[2] to make sure only it can access the read buffer at the time to release the memory used by the messages. EndExclusive() Read at the end of its work, cleaning the read buffer and flipping write/read ones, so now the write buffer is empty. Exclusive lock is unlocked after this.Exclusive Clear And Flip() - Sort() of the second (read) buffer is done under an exclusive lock[2], since it modifies the list, so it is not safe to read it.
When the access is finished End
This is used in the case when full synchronous flush is needed. Lock is used to control the thread-safe access for this data structure:
[1] Read-lock allows several threads to take it, but only if no exclusive lock is taken. Guarantees that no exclusive lock [2] will be taken during it. Read-lock is used in situations when it is ok for multiple threads to do some kind of access, like: add new elements (see Enqueue(Payload
[2] Exclusive lock is used when only one thread can enter and no read-locks are taken. This lock is used to cleanup the memory of the messages (see Begin
Implements
Inherited Members
Namespace: Unity.Logging
Assembly: solution.dll
Syntax
[BurstCompile]
public struct DispatchQueue : IDisposable
Constructors
Name | Description |
---|---|
Dispatch |
Constructor for Dispatch |
Properties
Name | Description |
---|---|
Is |
Is true if this struct was initialized. |
Total |
Total length of read-only and write buffers. Usually used for testing of internal state of the queue. |
Methods
Name | Description |
---|---|
Begin |
Puts Dispatch |
Begin |
Puts Dispatch |
Dispose() | Dispose call that will call Dispose for the lists (under lock) if IsCreated is true. IDisposable |
End |
Unlocks Dispatch |
End |
Unlocks Dispatch |
End |
Unlocks Dispatch |
Enqueue(Payload |
Adds new message to the write buffer under read lock. Gets the timestamp just before adding the message to the queue. |
Lock |
Enters the exclusive lock for Dispatch |