Replace Queue with DList
This commit is contained in:
		@@ -162,7 +162,7 @@ final class EpollLoop : SelectorLoop
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                else if (transport.output.length)
 | 
					                else if (transport.output.length)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    pendings.enqueue(transport);
 | 
					                    pendings.insertBack(transport);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (events[i].events & EPOLLOUT)
 | 
					            if (events[i].events & EPOLLOUT)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -273,7 +273,7 @@ final class IOCPLoop : Loop
 | 
				
			|||||||
        transport.socket.shutdown();
 | 
					        transport.socket.shutdown();
 | 
				
			||||||
        defaultAllocator.dispose(transport.socket);
 | 
					        defaultAllocator.dispose(transport.socket);
 | 
				
			||||||
        transport.exception = exception;
 | 
					        transport.exception = exception;
 | 
				
			||||||
        pendings.enqueue(transport);
 | 
					        pendings.insertBack(transport);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -316,11 +316,11 @@ final class IOCPLoop : Loop
 | 
				
			|||||||
                auto socket = listener.endAccept(overlapped);
 | 
					                auto socket = listener.endAccept(overlapped);
 | 
				
			||||||
                auto transport = defaultAllocator.make!StreamTransport(socket);
 | 
					                auto transport = defaultAllocator.make!StreamTransport(socket);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                connection.incoming.enqueue(transport);
 | 
					                connection.incoming.insertBack(transport);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                reify(transport, EventMask(Event.none), EventMask(Event.read, Event.write));
 | 
					                reify(transport, EventMask(Event.none), EventMask(Event.read, Event.write));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                pendings.enqueue(connection);
 | 
					                pendings.insertBack(connection);
 | 
				
			||||||
                listener.beginAccept(overlapped);
 | 
					                listener.beginAccept(overlapped);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case OverlappedSocketEvent.read:
 | 
					            case OverlappedSocketEvent.read:
 | 
				
			||||||
@@ -360,7 +360,7 @@ final class IOCPLoop : Loop
 | 
				
			|||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        transport.socket.beginReceive(transport.output[], overlapped);
 | 
					                        transport.socket.beginReceive(transport.output[], overlapped);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    pendings.enqueue(transport);
 | 
					                    pendings.insertBack(transport);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case OverlappedSocketEvent.write:
 | 
					            case OverlappedSocketEvent.write:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -279,7 +279,7 @@ final class KqueueLoop : SelectorLoop
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                else if (transport.output.length)
 | 
					                else if (transport.output.length)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    pendings.enqueue(transport);
 | 
					                    pendings.insertBack(transport);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (events[i].filter == EVFILT_WRITE)
 | 
					            else if (events[i].filter == EVFILT_WRITE)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -218,12 +218,12 @@ abstract class SelectorLoop : Loop
 | 
				
			|||||||
    this() @nogc
 | 
					    this() @nogc
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        super();
 | 
					        super();
 | 
				
			||||||
        connections = Array!SocketWatcher(maxEvents);
 | 
					        this.connections = Array!SocketWatcher(maxEvents);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ~this() @nogc
 | 
					    ~this() @nogc
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        foreach (ref connection; connections)
 | 
					        foreach (ref connection; this.connections[])
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // We want to free only the transports. ConnectionWatcher are
 | 
					            // We want to free only the transports. ConnectionWatcher are
 | 
				
			||||||
            // created by the user and should be freed by himself.
 | 
					            // created by the user and should be freed by himself.
 | 
				
			||||||
@@ -266,7 +266,7 @@ abstract class SelectorLoop : Loop
 | 
				
			|||||||
        transport.socket.shutdown();
 | 
					        transport.socket.shutdown();
 | 
				
			||||||
        defaultAllocator.dispose(transport.socket);
 | 
					        defaultAllocator.dispose(transport.socket);
 | 
				
			||||||
        transport.exception = exception;
 | 
					        transport.exception = exception;
 | 
				
			||||||
        pendings.enqueue(transport);
 | 
					        pendings.insertBack(transport);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -394,12 +394,12 @@ abstract class SelectorLoop : Loop
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            reify(transport, EventMask(Event.none), EventMask(Event.read, Event.write));
 | 
					            reify(transport, EventMask(Event.none), EventMask(Event.read, Event.write));
 | 
				
			||||||
            connection.incoming.enqueue(transport);
 | 
					            connection.incoming.insertBack(transport);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!connection.incoming.empty)
 | 
					        if (!connection.incoming.empty)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            pendings.enqueue(connection);
 | 
					            pendings.insertBack(connection);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -76,7 +76,7 @@ import std.typecons;
 | 
				
			|||||||
import tanya.async.transport;
 | 
					import tanya.async.transport;
 | 
				
			||||||
import tanya.async.watcher;
 | 
					import tanya.async.watcher;
 | 
				
			||||||
import tanya.container.buffer;
 | 
					import tanya.container.buffer;
 | 
				
			||||||
import tanya.container.queue;
 | 
					import tanya.container.list;
 | 
				
			||||||
import tanya.memory;
 | 
					import tanya.memory;
 | 
				
			||||||
import tanya.network.socket;
 | 
					import tanya.network.socket;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -163,7 +163,7 @@ abstract class Loop
 | 
				
			|||||||
    private bool done = true;
 | 
					    private bool done = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Pending watchers.
 | 
					    /// Pending watchers.
 | 
				
			||||||
    protected Queue!Watcher pendings;
 | 
					    protected DList!Watcher pendings;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Returns: Maximal event count can be got at a time
 | 
					     * Returns: Maximal event count can be got at a time
 | 
				
			||||||
@@ -188,7 +188,6 @@ abstract class Loop
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    this() @nogc
 | 
					    this() @nogc
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        pendings = Queue!Watcher();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -196,9 +195,9 @@ abstract class Loop
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    ~this() @nogc
 | 
					    ~this() @nogc
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        foreach (w; pendings)
 | 
					        for (; !this.pendings.empty; this.pendings.removeFront())
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            defaultAllocator.dispose(w);
 | 
					            defaultAllocator.dispose(this.pendings.front);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -213,9 +212,9 @@ abstract class Loop
 | 
				
			|||||||
            poll();
 | 
					            poll();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Invoke pendings
 | 
					            // Invoke pendings
 | 
				
			||||||
            foreach (ref w; this.pendings)
 | 
					            for (; !this.pendings.empty; this.pendings.removeFront())
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                w.invoke();
 | 
					                this.pendings.front.invoke();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        while (!this.done);
 | 
					        while (!this.done);
 | 
				
			||||||
@@ -244,7 +243,7 @@ abstract class Loop
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        auto loop = defaultAllocator.make!TestLoop;
 | 
					        auto loop = defaultAllocator.make!TestLoop;
 | 
				
			||||||
        auto watcher = defaultAllocator.make!DummyWatcher;
 | 
					        auto watcher = defaultAllocator.make!DummyWatcher;
 | 
				
			||||||
        loop.pendings.enqueue(watcher);
 | 
					        loop.pendings.insertBack(watcher);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        assert(!watcher.invoked);
 | 
					        assert(!watcher.invoked);
 | 
				
			||||||
        loop.run();
 | 
					        loop.run();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ import tanya.async.loop;
 | 
				
			|||||||
import tanya.async.protocol;
 | 
					import tanya.async.protocol;
 | 
				
			||||||
import tanya.async.transport;
 | 
					import tanya.async.transport;
 | 
				
			||||||
import tanya.container.buffer;
 | 
					import tanya.container.buffer;
 | 
				
			||||||
import tanya.container.queue;
 | 
					import tanya.container.list;
 | 
				
			||||||
import tanya.memory;
 | 
					import tanya.memory;
 | 
				
			||||||
import tanya.network.socket;
 | 
					import tanya.network.socket;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -91,7 +91,7 @@ abstract class SocketWatcher : Watcher
 | 
				
			|||||||
class ConnectionWatcher : SocketWatcher
 | 
					class ConnectionWatcher : SocketWatcher
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /// Incoming connection queue.
 | 
					    /// Incoming connection queue.
 | 
				
			||||||
    Queue!DuplexTransport incoming;
 | 
					    DList!DuplexTransport incoming;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private Protocol delegate() @nogc protocolFactory;
 | 
					    private Protocol delegate() @nogc protocolFactory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -102,7 +102,6 @@ class ConnectionWatcher : SocketWatcher
 | 
				
			|||||||
    this(Socket socket) @nogc
 | 
					    this(Socket socket) @nogc
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        super(socket);
 | 
					        super(socket);
 | 
				
			||||||
        incoming = Queue!DuplexTransport();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -124,10 +123,10 @@ class ConnectionWatcher : SocketWatcher
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    do
 | 
					    do
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        foreach (transport; incoming)
 | 
					        for (; !this.incoming.empty; this.incoming.removeFront())
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            transport.protocol = protocolFactory();
 | 
					            this.incoming.front.protocol = protocolFactory();
 | 
				
			||||||
            transport.protocol.connected(transport);
 | 
					            this.incoming.front.protocol.connected(this.incoming.front);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,7 @@
 | 
				
			|||||||
 * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/source/tanya/container/queue.d,
 | 
					 * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/source/tanya/container/queue.d,
 | 
				
			||||||
 *                 tanya/container/queue.d)
 | 
					 *                 tanya/container/queue.d)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					deprecated("Use tanya.container.list.DList instead")
 | 
				
			||||||
module tanya.container.queue;
 | 
					module tanya.container.queue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import tanya.algorithm.mutation;
 | 
					import tanya.algorithm.mutation;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user