Use only one queue for the async events
This commit is contained in:
parent
ab930657b6
commit
4de42ca227
@ -6,7 +6,7 @@
|
||||
* Copyright: Eugene Wissner 2016.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/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;
|
||||
|
||||
@ -159,7 +159,7 @@ class EpollLoop : SelectorLoop
|
||||
}
|
||||
else if (io.output.length)
|
||||
{
|
||||
swapPendings.enqueue(io);
|
||||
pendings.enqueue(io);
|
||||
}
|
||||
}
|
||||
else if (events[i].events & EPOLLOUT)
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Copyright: Eugene Wissner 2016.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/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;
|
||||
|
||||
@ -222,7 +222,7 @@ class IOCPLoop : Loop
|
||||
|
||||
reify(io, EventMask(Event.none), EventMask(Event.read, Event.write));
|
||||
|
||||
swapPendings.enqueue(connection);
|
||||
pendings.enqueue(connection);
|
||||
listener.beginAccept(overlapped);
|
||||
break;
|
||||
case OverlappedSocketEvent.read:
|
||||
@ -264,7 +264,7 @@ class IOCPLoop : Loop
|
||||
{
|
||||
transport.socket.beginReceive(io.output[], overlapped);
|
||||
}
|
||||
swapPendings.enqueue(io);
|
||||
pendings.enqueue(io);
|
||||
}
|
||||
break;
|
||||
case OverlappedSocketEvent.write:
|
||||
|
@ -271,7 +271,7 @@ class KqueueLoop : SelectorLoop
|
||||
}
|
||||
else if (io.output.length)
|
||||
{
|
||||
swapPendings.enqueue(io);
|
||||
pendings.enqueue(io);
|
||||
}
|
||||
}
|
||||
else if (events[i].filter == EVFILT_WRITE)
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Copyright: Eugene Wissner 2016.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/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;
|
||||
|
||||
@ -253,7 +253,7 @@ abstract class SelectorLoop : Loop
|
||||
|
||||
if (!connection.incoming.empty)
|
||||
{
|
||||
swapPendings.enqueue(connection);
|
||||
pendings.enqueue(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Copyright: Eugene Wissner 2016.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/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;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Copyright: Eugene Wissner 2016.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/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;
|
||||
@ -131,10 +131,7 @@ alias EventMask = BitFlags!Event;
|
||||
abstract class Loop
|
||||
{
|
||||
/// Pending watchers.
|
||||
protected Queue!Watcher* pendings;
|
||||
|
||||
/// Ditto.
|
||||
protected Queue!Watcher* swapPendings;
|
||||
protected Queue!Watcher pendings;
|
||||
|
||||
/**
|
||||
* Returns: Maximal event count can be got at a time
|
||||
@ -151,8 +148,7 @@ abstract class Loop
|
||||
*/
|
||||
this() @nogc
|
||||
{
|
||||
pendings = MmapPool.instance.make!(Queue!Watcher)(MmapPool.instance);
|
||||
swapPendings = MmapPool.instance.make!(Queue!Watcher)(MmapPool.instance);
|
||||
pendings = Queue!Watcher(MmapPool.instance);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,17 +156,10 @@ abstract class Loop
|
||||
*/
|
||||
~this() @nogc
|
||||
{
|
||||
foreach (w; *pendings)
|
||||
foreach (w; pendings)
|
||||
{
|
||||
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();
|
||||
|
||||
// Invoke pendings
|
||||
foreach (ref w; *swapPendings)
|
||||
foreach (ref w; pendings)
|
||||
{
|
||||
w.invoke();
|
||||
}
|
||||
swap(pendings, swapPendings);
|
||||
}
|
||||
while (!done_);
|
||||
}
|
||||
@ -255,7 +243,7 @@ abstract class Loop
|
||||
inout @safe pure nothrow @nogc
|
||||
{
|
||||
// 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);
|
||||
MmapPool.instance.dispose(watcher.transport);
|
||||
watcher.exception = exception;
|
||||
swapPendings.enqueue(watcher);
|
||||
pendings.enqueue(watcher);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Copyright: Eugene Wissner 2016.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/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;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Copyright: Eugene Wissner 2016.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/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;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Copyright: Eugene Wissner 2016.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/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;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Copyright: Eugene Wissner 2016.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/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;
|
||||
|
||||
@ -61,6 +61,7 @@ class ConnectionWatcher : Watcher
|
||||
*/
|
||||
this(Socket socket) @nogc
|
||||
{
|
||||
incoming = Queue!IOWatcher(MmapPool.instance);
|
||||
socket_ = socket;
|
||||
}
|
||||
|
||||
@ -233,7 +234,7 @@ class IOWatcher : ConnectionWatcher
|
||||
{
|
||||
if (output.length)
|
||||
{
|
||||
protocol.received(output[0..$]);
|
||||
protocol.received(output[0 .. $]);
|
||||
output.clear();
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user