Make all releaseRef() methods return a Boolean.
This commit is contained in:
parent
e4e78a860a
commit
201e4f6077
|
@ -103,8 +103,11 @@ interface EventDriverSockets {
|
||||||
|
|
||||||
Once the reference count reaches zero, all associated resources will be
|
Once the reference count reaches zero, all associated resources will be
|
||||||
freed and the resource descriptor gets invalidated.
|
freed and the resource descriptor gets invalidated.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Returns `false` $(I iff) the last reference was removed by this call.
|
||||||
*/
|
*/
|
||||||
void releaseRef(SocketFD descriptor);
|
bool releaseRef(SocketFD descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EventDriverDNS {
|
interface EventDriverDNS {
|
||||||
|
@ -134,8 +137,11 @@ interface EventDriverFiles {
|
||||||
|
|
||||||
Once the reference count reaches zero, all associated resources will be
|
Once the reference count reaches zero, all associated resources will be
|
||||||
freed and the resource descriptor gets invalidated.
|
freed and the resource descriptor gets invalidated.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Returns `false` $(I iff) the last reference was removed by this call.
|
||||||
*/
|
*/
|
||||||
void releaseRef(FileFD descriptor);
|
bool releaseRef(FileFD descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EventDriverEvents {
|
interface EventDriverEvents {
|
||||||
|
@ -154,8 +160,11 @@ interface EventDriverEvents {
|
||||||
|
|
||||||
Once the reference count reaches zero, all associated resources will be
|
Once the reference count reaches zero, all associated resources will be
|
||||||
freed and the resource descriptor gets invalidated.
|
freed and the resource descriptor gets invalidated.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Returns `false` $(I iff) the last reference was removed by this call.
|
||||||
*/
|
*/
|
||||||
void releaseRef(EventID descriptor);
|
bool releaseRef(EventID descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EventDriverSignals {
|
interface EventDriverSignals {
|
||||||
|
@ -170,8 +179,11 @@ interface EventDriverSignals {
|
||||||
|
|
||||||
Once the reference count reaches zero, all associated resources will be
|
Once the reference count reaches zero, all associated resources will be
|
||||||
freed and the resource descriptor gets invalidated.
|
freed and the resource descriptor gets invalidated.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Returns `false` $(I iff) the last reference was removed by this call.
|
||||||
*/
|
*/
|
||||||
void releaseRef(SignalListenID descriptor);
|
bool releaseRef(SignalListenID descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EventDriverTimers {
|
interface EventDriverTimers {
|
||||||
|
@ -192,8 +204,11 @@ interface EventDriverTimers {
|
||||||
|
|
||||||
Once the reference count reaches zero, all associated resources will be
|
Once the reference count reaches zero, all associated resources will be
|
||||||
freed and the resource descriptor gets invalidated.
|
freed and the resource descriptor gets invalidated.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Returns `false` $(I iff) the last reference was removed by this call.
|
||||||
*/
|
*/
|
||||||
void releaseRef(TimerID descriptor);
|
bool releaseRef(TimerID descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EventDriverWatchers {
|
interface EventDriverWatchers {
|
||||||
|
@ -208,6 +223,9 @@ interface EventDriverWatchers {
|
||||||
|
|
||||||
Once the reference count reaches zero, all associated resources will be
|
Once the reference count reaches zero, all associated resources will be
|
||||||
freed and the resource descriptor gets invalidated.
|
freed and the resource descriptor gets invalidated.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Returns `false` $(I iff) the last reference was removed by this call.
|
||||||
*/
|
*/
|
||||||
bool releaseRef(WatcherID descriptor);
|
bool releaseRef(WatcherID descriptor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ final class LibasyncEventDriverSockets : EventDriverSockets {
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
|
||||||
override void releaseRef(SocketFD descriptor)
|
override bool releaseRef(SocketFD descriptor)
|
||||||
{
|
{
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ final class LibasyncEventDriverFiles : EventDriverFiles {
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
|
||||||
override void releaseRef(FileFD descriptor)
|
override bool releaseRef(FileFD descriptor)
|
||||||
{
|
{
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ final class LibasyncEventDriverEvents : EventDriverEvents {
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
|
||||||
override void releaseRef(EventID descriptor)
|
override bool releaseRef(EventID descriptor)
|
||||||
{
|
{
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
@ -277,12 +277,17 @@ final class LibasyncEventDriverEvents : EventDriverEvents {
|
||||||
|
|
||||||
final class LibasyncEventDriverSignals : EventDriverSignals {
|
final class LibasyncEventDriverSignals : EventDriverSignals {
|
||||||
@safe: /*@nogc:*/ nothrow:
|
@safe: /*@nogc:*/ nothrow:
|
||||||
override void wait(int sig, SignalCallback on_signal)
|
override SignalListenID listen(int sig, SignalCallback on_signal)
|
||||||
{
|
{
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
|
||||||
override void cancelWait(int sig)
|
override void addRef(SignalListenID descriptor)
|
||||||
|
{
|
||||||
|
assert(false, "TODO!");
|
||||||
|
}
|
||||||
|
|
||||||
|
override bool releaseRef(SignalListenID descriptor)
|
||||||
{
|
{
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
@ -320,7 +325,7 @@ final class LibasyncEventDriverTimers : EventDriverTimers {
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
|
||||||
override void cancelWait(TimerID timer, TimerCallback callback)
|
override void cancelWait(TimerID timer)
|
||||||
{
|
{
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
@ -330,7 +335,7 @@ final class LibasyncEventDriverTimers : EventDriverTimers {
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
|
||||||
override void releaseRef(TimerID descriptor)
|
override bool releaseRef(TimerID descriptor)
|
||||||
{
|
{
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
@ -338,17 +343,7 @@ final class LibasyncEventDriverTimers : EventDriverTimers {
|
||||||
|
|
||||||
final class LibasyncEventDriverWatchers : EventDriverWatchers {
|
final class LibasyncEventDriverWatchers : EventDriverWatchers {
|
||||||
@safe: /*@nogc:*/ nothrow:
|
@safe: /*@nogc:*/ nothrow:
|
||||||
override WatcherID watchDirectory(string path, bool recursive)
|
override WatcherID watchDirectory(string path, bool recursive, FileChangesCallback callback)
|
||||||
{
|
|
||||||
assert(false, "TODO!");
|
|
||||||
}
|
|
||||||
|
|
||||||
override void wait(WatcherID watcher, FileChangesCallback callback)
|
|
||||||
{
|
|
||||||
assert(false, "TODO!");
|
|
||||||
}
|
|
||||||
|
|
||||||
override void cancelWait(WatcherID watcher)
|
|
||||||
{
|
{
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
@ -358,7 +353,7 @@ final class LibasyncEventDriverWatchers : EventDriverWatchers {
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
|
||||||
override void releaseRef(WatcherID descriptor)
|
override bool releaseRef(WatcherID descriptor)
|
||||||
{
|
{
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -735,7 +735,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
||||||
m_loop.m_fds[fd].refCount++;
|
m_loop.m_fds[fd].refCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
final override void releaseRef(SocketFD fd)
|
final override bool releaseRef(SocketFD fd)
|
||||||
{
|
{
|
||||||
auto pfd = () @trusted { return &m_loop.m_fds[fd]; } ();
|
auto pfd = () @trusted { return &m_loop.m_fds[fd]; } ();
|
||||||
assert(pfd.refCount > 0, "Releasing reference to unreferenced socket FD.");
|
assert(pfd.refCount > 0, "Releasing reference to unreferenced socket FD.");
|
||||||
|
@ -743,7 +743,9 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
||||||
m_loop.unregisterFD(fd);
|
m_loop.unregisterFD(fd);
|
||||||
m_loop.clearFD(fd);
|
m_loop.clearFD(fd);
|
||||||
closeSocket(fd);
|
closeSocket(fd);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SocketFD createSocket(AddressFamily family, int type)
|
private SocketFD createSocket(AddressFamily family, int type)
|
||||||
|
@ -1069,14 +1071,16 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop) : EventDriverEvents {
|
||||||
m_loop.m_fds[descriptor].refCount++;
|
m_loop.m_fds[descriptor].refCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
final override void releaseRef(EventID descriptor)
|
final override bool releaseRef(EventID descriptor)
|
||||||
{
|
{
|
||||||
assert(m_loop.m_fds[descriptor].refCount > 0, "Releasing reference to unreferenced event FD.");
|
assert(m_loop.m_fds[descriptor].refCount > 0, "Releasing reference to unreferenced event FD.");
|
||||||
if (--m_loop.m_fds[descriptor].refCount == 0) {
|
if (--m_loop.m_fds[descriptor].refCount == 0) {
|
||||||
m_loop.unregisterFD(descriptor);
|
m_loop.unregisterFD(descriptor);
|
||||||
m_loop.clearFD(descriptor);
|
m_loop.clearFD(descriptor);
|
||||||
close(descriptor);
|
close(descriptor);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1119,7 +1123,7 @@ final class PosixEventDriverSignals(Loop : PosixEventLoop) : EventDriverSignals
|
||||||
m_loop.m_fds[descriptor].refCount++;
|
m_loop.m_fds[descriptor].refCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
override void releaseRef(SignalListenID descriptor)
|
override bool releaseRef(SignalListenID descriptor)
|
||||||
{
|
{
|
||||||
FD fd = cast(FD)descriptor;
|
FD fd = cast(FD)descriptor;
|
||||||
assert(m_loop.m_fds[fd].refCount > 0, "Releasing reference to unreferenced event FD.");
|
assert(m_loop.m_fds[fd].refCount > 0, "Releasing reference to unreferenced event FD.");
|
||||||
|
@ -1127,7 +1131,9 @@ final class PosixEventDriverSignals(Loop : PosixEventLoop) : EventDriverSignals
|
||||||
m_loop.unregisterFD(fd);
|
m_loop.unregisterFD(fd);
|
||||||
m_loop.clearFD(fd);
|
m_loop.clearFD(fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSignal(FD fd)
|
private void onSignal(FD fd)
|
||||||
|
@ -1292,7 +1298,7 @@ final class PosixEventDriverWatchers(Loop : PosixEventLoop) : EventDriverWatcher
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
|
||||||
final override void releaseRef(WatcherID descriptor)
|
final override bool releaseRef(WatcherID descriptor)
|
||||||
{
|
{
|
||||||
assert(false, "TODO!");
|
assert(false, "TODO!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,7 @@ log("start task");
|
||||||
m_files[descriptor].refCount++;
|
m_files[descriptor].refCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
final override void releaseRef(FileFD descriptor)
|
final override bool releaseRef(FileFD descriptor)
|
||||||
{
|
{
|
||||||
auto f = () @trusted { return &m_files[descriptor]; } ();
|
auto f = () @trusted { return &m_files[descriptor]; } ();
|
||||||
if (!--f.refCount) {
|
if (!--f.refCount) {
|
||||||
|
@ -234,7 +234,9 @@ log("start task");
|
||||||
*f = FileInfo.init;
|
*f = FileInfo.init;
|
||||||
assert(!m_activeReads.contains(descriptor));
|
assert(!m_activeReads.contains(descriptor));
|
||||||
assert(!m_activeWrites.contains(descriptor));
|
assert(!m_activeWrites.contains(descriptor));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// private
|
/// private
|
||||||
|
|
|
@ -154,18 +154,21 @@ final class LoopTimeoutTimerDriver : EventDriverTimers {
|
||||||
m_timers[descriptor].refCount++;
|
m_timers[descriptor].refCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
final override void releaseRef(TimerID descriptor)
|
final override bool releaseRef(TimerID descriptor)
|
||||||
{
|
{
|
||||||
assert(descriptor != TimerID.init, "Invalid timer ID.");
|
assert(descriptor != TimerID.init, "Invalid timer ID.");
|
||||||
assert(descriptor in m_timers, "Unknown timer ID.");
|
assert(descriptor in m_timers, "Unknown timer ID.");
|
||||||
if (descriptor !in m_timers) return;
|
if (descriptor !in m_timers) return true;
|
||||||
|
|
||||||
auto tm = m_timers[descriptor];
|
auto tm = m_timers[descriptor];
|
||||||
if (!--tm.refCount) {
|
if (!--tm.refCount) {
|
||||||
if (tm.pending) stop(tm.id);
|
if (tm.pending) stop(tm.id);
|
||||||
m_timers.remove(descriptor);
|
m_timers.remove(descriptor);
|
||||||
() @trusted { scope (failure) assert(false); ms_allocator.dispose(tm); } ();
|
() @trusted { scope (failure) assert(false); ms_allocator.dispose(tm); } ();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue