[*] Improve ConsoleTTY perf
This commit is contained in:
parent
52f8556efe
commit
98f30cac51
@ -44,22 +44,22 @@ namespace Aurora::Console::ConsoleStd
|
||||
#if defined(ENABLE_STD_CONSOLE)
|
||||
|
||||
struct ConsoleHasDataLoopSource :
|
||||
#if defined(AURORA_COMPILER_MSVC)
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
virtual AuLoop::ILoopSource,
|
||||
#endif
|
||||
#endif
|
||||
virtual AuLoop::LSEvent
|
||||
{
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
ConsoleHasDataLoopSource() : LSEvent(false, false, true)
|
||||
{
|
||||
|
||||
}
|
||||
#else
|
||||
#else
|
||||
ConsoleHasDataLoopSource(int fd) : LSEvent(false, false, true)
|
||||
{
|
||||
handles = {fd, LSEvent::GetHandle()};
|
||||
handles = { AuUInt(fd), LSEvent::GetHandle() };
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool IsSignaled() override;
|
||||
AuLoop::ELoopSource GetType() override;
|
||||
@ -68,11 +68,38 @@ namespace Aurora::Console::ConsoleStd
|
||||
|
||||
private:
|
||||
|
||||
#if !defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
#if !defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
AuList<AuUInt> handles;
|
||||
virtual const AuList<AuUInt> &GetHandles() override;
|
||||
virtual const AuList<AuUInt>& GetHandles() override;
|
||||
virtual bool Singular() override;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct ConsoleSecondaryDataLoopSource :
|
||||
virtual AuLoop::ILoopSource,
|
||||
virtual AuLoop::LSEvent
|
||||
{
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
ConsoleSecondaryDataLoopSource(LSEvent *pAltHandle) : LSEvent(false, true, true)
|
||||
{
|
||||
handles = { /*pAltHandle->GetHandle()*/AuUInt(GetStdHandle(STD_INPUT_HANDLE)), LSEvent::GetHandle()};
|
||||
}
|
||||
#else
|
||||
ConsoleSecondaryDataLoopSource(int fd) : LSEvent(false, true, true)
|
||||
{
|
||||
handles = { AuUInt(fd), LSEvent::GetHandle() };
|
||||
}
|
||||
#endif
|
||||
|
||||
bool IsSignaled() override;
|
||||
AuLoop::ELoopSource GetType() override;
|
||||
bool OnTrigger(AuUInt handle) override;
|
||||
bool WaitOn(AuUInt32 timeout) override;
|
||||
|
||||
private:
|
||||
AuList<AuUInt> handles;
|
||||
virtual const AuList<AuUInt>& GetHandles() override;
|
||||
virtual bool Singular() override;
|
||||
#endif
|
||||
};
|
||||
|
||||
static AuByteBuffer gStdoutBuffer;
|
||||
@ -101,6 +128,7 @@ namespace Aurora::Console::ConsoleStd
|
||||
static StreamHandle_t gInputStream = DEFAULT_HANDLE_VAL;
|
||||
static StreamHandle_t gOutputStream = DEFAULT_HANDLE_VAL;
|
||||
static AuSPtr<ConsoleHasDataLoopSource> gLoopSource;
|
||||
static AuSPtr<ConsoleSecondaryDataLoopSource> gLoopSourceConTTY;
|
||||
static bool gCanonicalEnabled {};
|
||||
|
||||
static AuList<NoncanonicalInput> gCanonicalBuffer;
|
||||
@ -759,6 +787,37 @@ namespace Aurora::Console::ConsoleStd
|
||||
}
|
||||
#endif
|
||||
|
||||
bool ConsoleSecondaryDataLoopSource::IsSignaled()
|
||||
{
|
||||
return LSHandle::IsSignaled() ||
|
||||
gLineIndex;
|
||||
}
|
||||
|
||||
AuLoop::ELoopSource ConsoleSecondaryDataLoopSource::GetType()
|
||||
{
|
||||
return AuLoop::ELoopSource::eProcessStdIn;
|
||||
}
|
||||
|
||||
bool ConsoleSecondaryDataLoopSource::OnTrigger(AuUInt handle)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConsoleSecondaryDataLoopSource::WaitOn(AuUInt32 timeout)
|
||||
{
|
||||
return LSHandle::WaitOn(timeout);
|
||||
}
|
||||
|
||||
const AuList<AuUInt>& ConsoleSecondaryDataLoopSource::GetHandles()
|
||||
{
|
||||
return this->handles;
|
||||
}
|
||||
|
||||
bool ConsoleSecondaryDataLoopSource::Singular()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static void StartLogger()
|
||||
{
|
||||
if (gRuntimeConfig.console.enableStdPassthrough == gRuntimeConfig.console.enableStdOut)
|
||||
@ -878,13 +937,21 @@ namespace Aurora::Console::ConsoleStd
|
||||
gOutputStream = STDOUT_FILENO;
|
||||
|
||||
#endif
|
||||
|
||||
gLoopSource = AuMakeShared<ConsoleHasDataLoopSource>(
|
||||
|
||||
gLoopSource = AuMakeSharedPanic<ConsoleHasDataLoopSource>(
|
||||
#if !defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
gInputStream
|
||||
#endif
|
||||
);
|
||||
|
||||
gLoopSourceConTTY = AuMakeSharedPanic<ConsoleSecondaryDataLoopSource>(
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
gLoopSource.get()
|
||||
#else
|
||||
gInputStream
|
||||
#endif
|
||||
);
|
||||
|
||||
SysAssert(gInputStream != DEFAULT_HANDLE_VAL, "Couldn't allocate input stream handler");
|
||||
SysAssert(gOutputStream != DEFAULT_HANDLE_VAL, "Couldn't allocate output stream handler");
|
||||
|
||||
@ -1611,15 +1678,32 @@ namespace Aurora::Console::ConsoleStd
|
||||
|
||||
gConsoleStarted = false;
|
||||
#endif
|
||||
|
||||
|
||||
AuResetMember(gLoopSource);
|
||||
AuResetMember(gLoopSourceConTTY);
|
||||
}
|
||||
|
||||
|
||||
AuLoop::ILSEvent* GetConTTYEvent()
|
||||
{
|
||||
return gLoopSourceConTTY.get();
|
||||
}
|
||||
|
||||
AuSPtr<AuLoop::ILoopSource> GetLoopSource()
|
||||
{
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
if (gCanonicalEnabled)
|
||||
{
|
||||
return gLoopSourceConTTY;
|
||||
}
|
||||
#endif
|
||||
return gLoopSource;
|
||||
}
|
||||
|
||||
AuSPtr<AuLoop::ILoopSource> GetLoopSourceConTTY()
|
||||
{
|
||||
return gLoopSourceConTTY;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void Pump()
|
||||
@ -1646,5 +1730,16 @@ namespace Aurora::Console::ConsoleStd
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
AuSPtr<AuLoop::ILoopSource> GetLoopSourceConTTY()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
AuLoop::ILSEvent* GetConTTYEvent()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -14,8 +14,9 @@ namespace Aurora::Console::ConsoleStd
|
||||
void Exit();
|
||||
void Flush();
|
||||
void Start();
|
||||
|
||||
|
||||
AuSPtr<AuLoop::ILoopSource> GetLoopSource();
|
||||
AuSPtr<AuLoop::ILoopSource> GetLoopSourceConTTY();
|
||||
|
||||
AuUInt32 WriteStdOutBlocking2(const void *data, AuUInt32 length);
|
||||
|
||||
@ -29,6 +30,8 @@ namespace Aurora::Console::ConsoleStd
|
||||
|
||||
inline bool gSupportsColorOutput { true };
|
||||
|
||||
AuLoop::ILSEvent* GetConTTYEvent();
|
||||
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
void ProcessCanonical(HANDLE h);
|
||||
#endif
|
||||
|
@ -417,6 +417,11 @@ namespace Aurora::Console::ConsoleTTY
|
||||
AuConsole::ConsoleMessage msg2(msg);
|
||||
msg2.line = msg.ToConsole();
|
||||
AuTryInsert(this->messagesPending, msg2); // TODO: !
|
||||
|
||||
if (auto pEvent = ConsoleStd::GetConTTYEvent())
|
||||
{
|
||||
pEvent->Set();
|
||||
}
|
||||
}
|
||||
|
||||
void TTYConsole::BufferMessage(const AuConsole::ConsoleMessage &msg, const AuString &input)
|
||||
@ -426,6 +431,11 @@ namespace Aurora::Console::ConsoleTTY
|
||||
AuConsole::ConsoleMessage msg2(msg);
|
||||
msg2.line = input;
|
||||
AuTryInsert(this->messagesPending, msg2); // TODO: !
|
||||
|
||||
if (auto pEvent = ConsoleStd::GetConTTYEvent())
|
||||
{
|
||||
pEvent->Set();
|
||||
}
|
||||
}
|
||||
|
||||
void TTYConsole::NoncanonicalTick()
|
||||
@ -2373,6 +2383,7 @@ namespace Aurora::Console::ConsoleTTY
|
||||
{
|
||||
while (AuIsThreadRunning())
|
||||
{
|
||||
#if 0
|
||||
if (auto pLoopSource = AuConsole::StdInBufferLoopSource())
|
||||
{
|
||||
pLoopSource->WaitOn(1000 / 20);
|
||||
@ -2381,6 +2392,23 @@ namespace Aurora::Console::ConsoleTTY
|
||||
{
|
||||
AuThreading::Sleep(1000 / 20);
|
||||
}
|
||||
#else
|
||||
if (auto pLoopSource = ConsoleStd::GetLoopSourceConTTY())
|
||||
{
|
||||
if (gTTYConsole.uxModeFlipped)
|
||||
{
|
||||
pLoopSource->WaitOn(5000);
|
||||
}
|
||||
else
|
||||
{
|
||||
pLoopSource->WaitOn(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AuThreading::Sleep(1000 / 20);
|
||||
}
|
||||
#endif
|
||||
gTTYConsole.Pump();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user