[+] Added extended IO apis

> StartSimpleLSWatchEx
> StartSimpleIOWatchEx
> StartIOWatchEx
[*] Update README
This commit is contained in:
Reece Wilson 2022-06-28 15:57:29 +01:00
parent 250d3fd11e
commit 70418df761
13 changed files with 141 additions and 29 deletions

View File

@ -25,8 +25,13 @@ namespace Aurora::IO
virtual AuUInt64 GetOwnedThreadId () = 0; virtual AuUInt64 GetOwnedThreadId () = 0;
virtual AuSPtr<IIOProcessorItem> StartIOWatch (const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOEventListener> &listener) = 0; virtual AuSPtr<IIOProcessorItem> StartIOWatch (const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOEventListener> &listener) = 0;
virtual AuSPtr<IIOProcessorItem> StartIOWatchEx (const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOEventListener> &listener, bool singleshot) = 0;
virtual AuSPtr<IIOProcessorItem> StartSimpleIOWatch (const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOSimpleEventListener> &listener) = 0; virtual AuSPtr<IIOProcessorItem> StartSimpleIOWatch (const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOSimpleEventListener> &listener) = 0;
virtual AuSPtr<IIOProcessorItem> StartSimpleIOWatchEx(const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOSimpleEventListener> &listener, bool singleshot) = 0;
virtual AuSPtr<IIOProcessorItem> StartSimpleLSWatch (const AuSPtr<Loop::ILoopSource> &source, const AuSPtr<IIOSimpleEventListener> &listener) = 0; virtual AuSPtr<IIOProcessorItem> StartSimpleLSWatch (const AuSPtr<Loop::ILoopSource> &source, const AuSPtr<IIOSimpleEventListener> &listener) = 0;
virtual AuSPtr<IIOProcessorItem> StartSimpleLSWatchEx(const AuSPtr<Loop::ILoopSource> &source, const AuSPtr<IIOSimpleEventListener> &listener, bool singleshot, AuUInt32 msTimeout = 0) = 0;
virtual bool SubmitIOWorkItem (const AuSPtr<IIOProcessorWorkUnit> &work) = 0; virtual bool SubmitIOWorkItem (const AuSPtr<IIOProcessorWorkUnit> &work) = 0;

View File

@ -16,4 +16,5 @@ namespace Aurora::IO
}; };
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSource(const AuSPtr<Loop::ILoopSource> &ptr); AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSource(const AuSPtr<Loop::ILoopSource> &ptr);
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSourceEx(const AuSPtr<Loop::ILoopSource>& ptr, AuUInt32 msTimeout);
} }

View File

@ -24,6 +24,7 @@ namespace Aurora::IO
AUI_METHOD(bool, IsRunOnSelfIO, ()), AUI_METHOD(bool, IsRunOnSelfIO, ()),
AUI_METHOD(AuSPtr<Loop::ILoopSource>, GetSelfIOSource, ()), AUI_METHOD(AuSPtr<Loop::ILoopSource>, GetSelfIOSource, ()),
AUI_METHOD(AuUInt32, IOTimeoutInMS, ()),
AUI_METHOD(bool, IsRunOnSelfIOCheckedOnTimerTick, ()), AUI_METHOD(bool, IsRunOnSelfIOCheckedOnTimerTick, ()),
AUI_METHOD(bool, ApplyRateLimit, ()) AUI_METHOD(bool, ApplyRateLimit, ())

View File

@ -1,4 +1,5 @@
## PREALPHA (in-dev, missing polish and APIs are volatile) ## PREALPHA (in-dev, missing polish and APIs are volatile)
## Minimum viable product ETA: September 2022
## AuroraRuntime ## AuroraRuntime
@ -50,6 +51,18 @@ Build Pipeline: [Aurora Build](https://git.reece.sx/AuroraPipeline/Build) (Lua/P
Donate / Other Links: [Reece.SX](https://reece.sx/#contact) \ Donate / Other Links: [Reece.SX](https://reece.sx/#contact) \
Discord: [Invite](https://discord.gg/XYjCGWWa4J) Discord: [Invite](https://discord.gg/XYjCGWWa4J)
## Support
| Platform | Support |
| ----------- | ------- |
| NT/Win32-like |✅ |
| NT/UWP | 🕖 |
| NT/GameOS|❌ |
| Linux |🕖 |
| FreeBSD 9 | ❌ |
| FreeBSD 11 | ❌ |
| XNU/NS-like | ❌ |
## Performance ## Performance
Performance of each system should ideally be that of the best implementation on the platform, Performance of each system should ideally be that of the best implementation on the platform,

View File

@ -105,6 +105,7 @@ namespace Aurora::IO
this->bytesWrittenLimit_ = request.lengthOrZero; this->bytesWrittenLimit_ = request.lengthOrZero;
this->asyncTransaction_ = request.asyncTransaction; this->asyncTransaction_ = request.asyncTransaction;
this->asyncAdapter_ = NewAsyncStreamAdapter(request.asyncTransaction, request.isStream); this->asyncAdapter_ = NewAsyncStreamAdapter(request.asyncTransaction, request.isStream);
SysAssert(this->asyncAdapter_);
this->asyncStreamReader_ = this->asyncAdapter_->ToStreamReader(); this->asyncStreamReader_ = this->asyncAdapter_->ToStreamReader();
} }

View File

@ -297,6 +297,8 @@ namespace Aurora::IO
} }
} }
auto hasRemoved = this->items.crossThreadAbort.size();
for (auto itr = this->items.crossThreadAbort.begin(); itr != this->items.crossThreadAbort.end(); ) for (auto itr = this->items.crossThreadAbort.begin(); itr != this->items.crossThreadAbort.end(); )
{ {
bool fatal = itr->second; bool fatal = itr->second;
@ -307,6 +309,11 @@ namespace Aurora::IO
itr = this->items.crossThreadAbort.erase(itr); itr = this->items.crossThreadAbort.erase(itr);
} }
if (hasRemoved)
{
ToQueue()->Commit();
}
} }
@ -618,7 +625,8 @@ namespace Aurora::IO
return {}; return {};
} }
AuSPtr<IIOProcessorItem> IOProcessor::StartIOWatch(const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOEventListener> &listener)
AuSPtr<IIOProcessorItem> IOProcessor::StartIOWatchEx(const AuSPtr<IIOWaitableItem>& object, const AuSPtr<IIOEventListener>& listener, bool singleshot)
{ {
if (!CheckThread()) if (!CheckThread())
{ {
@ -629,6 +637,7 @@ namespace Aurora::IO
item->parent = this; item->parent = this;
item->listener = listener; item->listener = listener;
item->item = object; item->item = object;
item->singleshot = true;
AU_LOCK_GUARD(this->items.mutex); AU_LOCK_GUARD(this->items.mutex);
@ -661,13 +670,25 @@ namespace Aurora::IO
return {}; return {};
} }
auto timeout = object->IOTimeoutInMS();
if (timeout)
{
if (!this->ToQueue()->SourceAddWithTimeout(src, timeout))
{
SysPushErrorNested("IO Error");
return {};
}
}
else
{
if (!this->ToQueue()->SourceAdd(src)) if (!this->ToQueue()->SourceAdd(src))
{ {
SysPushErrorNested("IO Error"); SysPushErrorNested("IO Error");
return {}; return {};
} }
}
if (!this->ToQueue()->AddCallback(src, item)) if (!this->ToQueue()->AddCallbackEx(src, item))
{ {
SysPushErrorNested("IO Error"); SysPushErrorNested("IO Error");
SysAssert(this->ToQueue()->SourceRemove(src)); SysAssert(this->ToQueue()->SourceRemove(src));
@ -690,7 +711,7 @@ namespace Aurora::IO
return item; return item;
} }
AuSPtr<IIOProcessorItem> IOProcessor::StartSimpleIOWatch(const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOSimpleEventListener> &listener) AuSPtr<IIOProcessorItem> IOProcessor::StartSimpleIOWatchEx(const AuSPtr<IIOWaitableItem>& object, const AuSPtr<IIOSimpleEventListener>& listener, bool singleshot)
{ {
auto adapater = DesimplifyIOEventListenerAdapater(listener); auto adapater = DesimplifyIOEventListenerAdapater(listener);
if (!adapater) if (!adapater)
@ -699,19 +720,34 @@ namespace Aurora::IO
return {}; return {};
} }
return this->StartIOWatch(object, adapater); return this->StartIOWatchEx(object, adapater, singleshot);
} }
AuSPtr<IIOProcessorItem> IOProcessor::StartSimpleLSWatch(const AuSPtr<Loop::ILoopSource> &source, const AuSPtr<IIOSimpleEventListener> &listener) AuSPtr<IIOProcessorItem> IOProcessor::StartSimpleLSWatchEx(const AuSPtr<Loop::ILoopSource>& source, const AuSPtr<IIOSimpleEventListener>& listener, bool singleshot, AuUInt32 msTimeout)
{ {
auto sourceAdapter = NewWaitableLoopSource(source); auto sourceAdapter = NewWaitableLoopSourceEx(source, msTimeout);
if (!sourceAdapter) if (!sourceAdapter)
{ {
SysPushErrorMem(); SysPushErrorMem();
return {}; return {};
} }
return this->StartSimpleIOWatch(sourceAdapter, listener); return this->StartSimpleIOWatchEx(sourceAdapter, listener, singleshot);
}
AuSPtr<IIOProcessorItem> IOProcessor::StartIOWatch(const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOEventListener> &listener)
{
return StartIOWatchEx(object, listener, false);
}
AuSPtr<IIOProcessorItem> IOProcessor::StartSimpleIOWatch(const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOSimpleEventListener> &listener)
{
return this->StartSimpleIOWatchEx(object, listener, false);
}
AuSPtr<IIOProcessorItem> IOProcessor::StartSimpleLSWatch(const AuSPtr<Loop::ILoopSource> &source, const AuSPtr<IIOSimpleEventListener> &listener)
{
return this->StartSimpleLSWatchEx(source, listener, false, 0);
} }
AuSPtr<IIOPipeProcessor> IOProcessor::ToPipeProcessor() AuSPtr<IIOPipeProcessor> IOProcessor::ToPipeProcessor()

View File

@ -67,6 +67,11 @@ namespace Aurora::IO
AuSPtr<IIOProcessorItem> StartSimpleIOWatch(const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOSimpleEventListener> &listener) override; AuSPtr<IIOProcessorItem> StartSimpleIOWatch(const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOSimpleEventListener> &listener) override;
AuSPtr<IIOProcessorItem> StartSimpleLSWatch(const AuSPtr<Loop::ILoopSource> &source, const AuSPtr<IIOSimpleEventListener> &listener) override; AuSPtr<IIOProcessorItem> StartSimpleLSWatch(const AuSPtr<Loop::ILoopSource> &source, const AuSPtr<IIOSimpleEventListener> &listener) override;
AuSPtr<IIOProcessorItem> StartIOWatchEx (const AuSPtr<IIOWaitableItem> &object, const AuSPtr<IIOEventListener> &listener, bool singleshot) override;
AuSPtr<IIOProcessorItem> StartSimpleIOWatchEx(const AuSPtr<IIOWaitableItem>& object, const AuSPtr<IIOSimpleEventListener>& listener, bool singleshot) override;
AuSPtr<IIOProcessorItem> StartSimpleLSWatchEx(const AuSPtr<Loop::ILoopSource>& source, const AuSPtr<IIOSimpleEventListener>& listener, bool singleshot, AuUInt32 msTimeout) override;
AuSPtr<IIOPipeProcessor> ToPipeProcessor() override; AuSPtr<IIOPipeProcessor> ToPipeProcessor() override;
AuSPtr<AuLoop::ILoopQueue> ToQueue() override; AuSPtr<AuLoop::ILoopQueue> ToQueue() override;

View File

@ -36,12 +36,34 @@ namespace Aurora::IO
return this->parent->items.ScheduleFinish(AuSharedFromThis(), true); return this->parent->items.ScheduleFinish(AuSharedFromThis(), true);
} }
bool IOProcessorItem::OnFinished(const AuSPtr<AuLoop::ILoopSource> &source)
bool IOProcessorItem::OnFinished(const AuSPtr<AuLoop::ILoopSource>& source, AuUInt8 pos)
{ {
if (this->singleshot)
{
if (AuExchange(this->triggered, true))
{
StopWatch();
return true;
}
}
IOAlert(false); IOAlert(false);
if (this->singleshot)
{
StopWatch();
}
return false; return false;
} }
void IOProcessorItem::OnTimeout(const AuSPtr<AuLoop::ILoopSource>& source)
{
SysPushErrorIO("IO Timeout");
this->FailWatch();
}
void IOProcessorItem::InvokeManualTick() void IOProcessorItem::InvokeManualTick()
{ {
IOAlert(true); IOAlert(true);

View File

@ -11,15 +11,18 @@ namespace Aurora::IO
{ {
struct IOProcessor; struct IOProcessor;
struct IOProcessorItem : AuLoop::ILoopSourceSubscriber, IIOProcessorItem, AuEnableSharedFromThis<IOProcessorItem> struct IOProcessorItem : AuLoop::ILoopSourceSubscriberEx, IIOProcessorItem, AuEnableSharedFromThis<IOProcessorItem>
{ {
IOProcessor *parent; IOProcessor *parent;
bool singleshot{};
bool triggered{};
AuSPtr<IIOWaitableItem> item; AuSPtr<IIOWaitableItem> item;
AuSPtr<IIOEventListener> listener; AuSPtr<IIOEventListener> listener;
// ILoopSourceSubscriber // ILoopSourceSubscriber
bool OnFinished(const AuSPtr<AuLoop::ILoopSource> &source) override; bool OnFinished(const AuSPtr<AuLoop::ILoopSource> &source, AuUInt8 pos) override;
void OnTimeout(const AuSPtr<AuLoop::ILoopSource>& source) override;
// IIOProcessorItem // IIOProcessorItem
virtual bool StopWatch() override; virtual bool StopWatch() override;

View File

@ -16,6 +16,11 @@ namespace Aurora::IO
} }
IOWatachableIOLoopSource::IOWatachableIOLoopSource(const AuSPtr<Loop::ILoopSource>& source, AuUInt32 ioTimeoutMS) : source(source), ioTimeoutMS(ioTimeoutMS)
{
}
bool IOWatachableIOLoopSource::IsRunOnOtherTick() bool IOWatachableIOLoopSource::IsRunOnOtherTick()
{ {
return {}; return {};
@ -66,8 +71,18 @@ namespace Aurora::IO
return true; return true;
} }
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSource(const AuSPtr<Loop::ILoopSource> &ptr) AuUInt32 IOWatachableIOLoopSource::IOTimeoutInMS()
{
return this->ioTimeoutMS;
}
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSource(const AuSPtr<Loop::ILoopSource>& ptr)
{ {
return AuMakeShared<IOWatachableIOLoopSource>(ptr); return AuMakeShared<IOWatachableIOLoopSource>(ptr);
} }
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSourceEx(const AuSPtr<Loop::ILoopSource>& ptr, AuUInt32 msTimeout)
{
return AuMakeShared<IOWatachableIOLoopSource>(ptr, msTimeout);
}
} }

View File

@ -11,7 +11,8 @@ namespace Aurora::IO
{ {
struct IOWatachableIOLoopSource : IIOWatachableIOLoopSource struct IOWatachableIOLoopSource : IIOWatachableIOLoopSource
{ {
IOWatachableIOLoopSource(const AuSPtr<Loop::ILoopSource> &source); IOWatachableIOLoopSource(const AuSPtr<Loop::ILoopSource>& source);
IOWatachableIOLoopSource(const AuSPtr<Loop::ILoopSource>& source, AuUInt32 ioTimeoutMS);
bool IsRunOnOtherTick() override; bool IsRunOnOtherTick() override;
bool IsRunOnTick() override; bool IsRunOnTick() override;
@ -24,10 +25,12 @@ namespace Aurora::IO
bool ApplyRateLimit() override; bool ApplyRateLimit() override;
AuUInt32 IOTimeoutInMS() override;
AuSPtr<Loop::ILoopSource> GetLoopSource() override; AuSPtr<Loop::ILoopSource> GetLoopSource() override;
AuSPtr<Loop::ILoopSource> SetLoopSource(const AuSPtr<Loop::ILoopSource> &ls) override; AuSPtr<Loop::ILoopSource> SetLoopSource(const AuSPtr<Loop::ILoopSource> &ls) override;
bool IsRunOnSelfIOCheckedOnTimerTick() override; bool IsRunOnSelfIOCheckedOnTimerTick() override;
AuSPtr<Loop::ILoopSource> source; AuSPtr<Loop::ILoopSource> source;
AuUInt32 ioTimeoutMS{};
}; };
} }

View File

@ -61,6 +61,11 @@ namespace Aurora::IO
return false; return false;
} }
AuUInt32 IOWaitableIOTimer::IOTimeoutInMS()
{
return 0;
}
AuUInt64 IOWaitableIOTimer::SetConstantTick(AuUInt64 ns) AuUInt64 IOWaitableIOTimer::SetConstantTick(AuUInt64 ns)
{ {
auto old = AuExchange(this->constantTickNs, ns); auto old = AuExchange(this->constantTickNs, ns);

View File

@ -26,6 +26,8 @@ namespace Aurora::IO
bool IsRunOnSelfIOCheckedOnTimerTick() override; bool IsRunOnSelfIOCheckedOnTimerTick() override;
bool ApplyRateLimit() override; bool ApplyRateLimit() override;
AuUInt32 IOTimeoutInMS() override;
AuUInt64 SetConstantTick(AuUInt64 ns) override; AuUInt64 SetConstantTick(AuUInt64 ns) override;
AuUInt64 SetTargetTimeAbs(AuUInt64 ns) override; AuUInt64 SetTargetTimeAbs(AuUInt64 ns) override;