Use only one queue for the async events

This commit is contained in:
Eugen Wissner 2017-01-12 09:09:33 +01:00
parent ab930657b6
commit 4de42ca227
10 changed files with 22 additions and 33 deletions

View File

@ -6,7 +6,7 @@
* Copyright: Eugene Wissner 2016. * Copyright: Eugene Wissner 2016.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
*/ */
module tanya.async.event.epoll; module tanya.async.event.epoll;
@ -159,7 +159,7 @@ class EpollLoop : SelectorLoop
} }
else if (io.output.length) else if (io.output.length)
{ {
swapPendings.enqueue(io); pendings.enqueue(io);
} }
} }
else if (events[i].events & EPOLLOUT) else if (events[i].events & EPOLLOUT)

View File

@ -6,7 +6,7 @@
* Copyright: Eugene Wissner 2016. * Copyright: Eugene Wissner 2016.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
*/ */
module tanya.async.event.iocp; module tanya.async.event.iocp;
@ -222,7 +222,7 @@ class IOCPLoop : Loop
reify(io, EventMask(Event.none), EventMask(Event.read, Event.write)); reify(io, EventMask(Event.none), EventMask(Event.read, Event.write));
swapPendings.enqueue(connection); pendings.enqueue(connection);
listener.beginAccept(overlapped); listener.beginAccept(overlapped);
break; break;
case OverlappedSocketEvent.read: case OverlappedSocketEvent.read:
@ -264,7 +264,7 @@ class IOCPLoop : Loop
{ {
transport.socket.beginReceive(io.output[], overlapped); transport.socket.beginReceive(io.output[], overlapped);
} }
swapPendings.enqueue(io); pendings.enqueue(io);
} }
break; break;
case OverlappedSocketEvent.write: case OverlappedSocketEvent.write:

View File

@ -271,7 +271,7 @@ class KqueueLoop : SelectorLoop
} }
else if (io.output.length) else if (io.output.length)
{ {
swapPendings.enqueue(io); pendings.enqueue(io);
} }
} }
else if (events[i].filter == EVFILT_WRITE) else if (events[i].filter == EVFILT_WRITE)

View File

@ -6,7 +6,7 @@
* Copyright: Eugene Wissner 2016. * Copyright: Eugene Wissner 2016.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
*/ */
module tanya.async.event.selector; module tanya.async.event.selector;
@ -253,7 +253,7 @@ abstract class SelectorLoop : Loop
if (!connection.incoming.empty) if (!connection.incoming.empty)
{ {
swapPendings.enqueue(connection); pendings.enqueue(connection);
} }
} }
} }

View File

@ -6,7 +6,7 @@
* Copyright: Eugene Wissner 2016. * Copyright: Eugene Wissner 2016.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
*/ */
module tanya.async.iocp; module tanya.async.iocp;

View File

@ -6,7 +6,7 @@
* Copyright: Eugene Wissner 2016. * Copyright: Eugene Wissner 2016.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
* *
* --- * ---
* import tanya.async; * import tanya.async;
@ -131,10 +131,7 @@ alias EventMask = BitFlags!Event;
abstract class Loop abstract class Loop
{ {
/// Pending watchers. /// Pending watchers.
protected Queue!Watcher* pendings; protected Queue!Watcher pendings;
/// Ditto.
protected Queue!Watcher* swapPendings;
/** /**
* Returns: Maximal event count can be got at a time * Returns: Maximal event count can be got at a time
@ -151,8 +148,7 @@ abstract class Loop
*/ */
this() @nogc this() @nogc
{ {
pendings = MmapPool.instance.make!(Queue!Watcher)(MmapPool.instance); pendings = Queue!Watcher(MmapPool.instance);
swapPendings = MmapPool.instance.make!(Queue!Watcher)(MmapPool.instance);
} }
/** /**
@ -160,17 +156,10 @@ abstract class Loop
*/ */
~this() @nogc ~this() @nogc
{ {
foreach (w; *pendings) foreach (w; pendings)
{ {
MmapPool.instance.dispose(w); MmapPool.instance.dispose(w);
} }
MmapPool.instance.dispose(pendings);
foreach (w; *swapPendings)
{
MmapPool.instance.dispose(w);
}
MmapPool.instance.dispose(swapPendings);
} }
/** /**
@ -184,11 +173,10 @@ abstract class Loop
poll(); poll();
// Invoke pendings // Invoke pendings
foreach (ref w; *swapPendings) foreach (ref w; pendings)
{ {
w.invoke(); w.invoke();
} }
swap(pendings, swapPendings);
} }
while (!done_); while (!done_);
} }
@ -255,7 +243,7 @@ abstract class Loop
inout @safe pure nothrow @nogc inout @safe pure nothrow @nogc
{ {
// Don't block if we have to do. // Don't block if we have to do.
return swapPendings.empty ? blockTime_ : Duration.zero; return pendings.empty ? blockTime_ : Duration.zero;
} }
/** /**
@ -285,7 +273,7 @@ abstract class Loop
defaultAllocator.dispose(watcher.socket); defaultAllocator.dispose(watcher.socket);
MmapPool.instance.dispose(watcher.transport); MmapPool.instance.dispose(watcher.transport);
watcher.exception = exception; watcher.exception = exception;
swapPendings.enqueue(watcher); pendings.enqueue(watcher);
} }
/** /**

View File

@ -6,7 +6,7 @@
* Copyright: Eugene Wissner 2016. * Copyright: Eugene Wissner 2016.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
*/ */
module tanya.async; module tanya.async;

View File

@ -6,7 +6,7 @@
* Copyright: Eugene Wissner 2016. * Copyright: Eugene Wissner 2016.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
*/ */
module tanya.async.protocol; module tanya.async.protocol;

View File

@ -6,7 +6,7 @@
* Copyright: Eugene Wissner 2016. * Copyright: Eugene Wissner 2016.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
*/ */
module tanya.async.transport; module tanya.async.transport;

View File

@ -6,7 +6,7 @@
* Copyright: Eugene Wissner 2016. * Copyright: Eugene Wissner 2016.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:belka@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
*/ */
module tanya.async.watcher; module tanya.async.watcher;
@ -61,6 +61,7 @@ class ConnectionWatcher : Watcher
*/ */
this(Socket socket) @nogc this(Socket socket) @nogc
{ {
incoming = Queue!IOWatcher(MmapPool.instance);
socket_ = socket; socket_ = socket;
} }
@ -233,7 +234,7 @@ class IOWatcher : ConnectionWatcher
{ {
if (output.length) if (output.length)
{ {
protocol.received(output[0..$]); protocol.received(output[0 .. $]);
output.clear(); output.clear();
} }
else else