/// <summary> /// Add a P2PPacket to the queue /// </summary> public void Enqueue(P2Packet packet) { lock (_lock) // Lock for thread safety { P2PPacketNode newNode = new P2PPacketNode(packet); _len++; if (_head == null) { _head = newNode; _tail = newNode; return; } _tail.Next = newNode; _tail = newNode; } }
/// <summary> /// Clear all nodes from the queue /// </summary> public void Clear() { object clearLock = new object(); lock (clearLock) { P2Packet?packet = Dequeue(); while (packet != null) { packet = Dequeue(); } // Guarantee clearing of head, tail, and length _head = null; _tail = null; _len = 0; } }
/// <summary> /// Remove a P2PPacket from the queue /// </summary> public P2Packet?Dequeue() { lock (_lock) // Lock for thread safety { // Only human; probably unnecessary, but safer or something if (_len > 0) { _len--; } if (_head != null) { P2PPacketNode node = _head; P2Packet packet = _head.Packet; _head = _head.Next; node.Dispose(); return(packet); } return(null); } }
public void Dispose() { _next = null; }