[+] AuOutputOfs OutputOfResult should have a lock for multithread consumption

This commit is contained in:
Reece Wilson 2024-09-05 18:20:12 +01:00
parent 830286de46
commit 3472665c9f
2 changed files with 43 additions and 9 deletions

View File

@ -18,12 +18,16 @@ namespace Aurora::Processes
struct OutputOfResult
{
bool bFailed {};
bool bNoStart {};
AuString strStdout;
AuString strStderr;
AuUInt uExitCode {};
AuSInt sExitCode {};
// Lockable object for reading strStdout and strStderr between threads.
/*AuFutexMutex*/ Aurora::Threading::Waitables::FutexWaitableNoVTblMovable lock;
bool bFailed { };
bool bNoStart { };
bool bPipeOutOOM { };
bool bPipeErrOOM { };
AuString strStdout { };
AuString strStderr { };
AuUInt uExitCode { };
AuSInt sExitCode { };
};
struct IAsyncOutputOf
@ -39,9 +43,13 @@ namespace Aurora::Processes
AURT_ADD_USR_DATA_EXP(this->ToCompletionGroupHandle());
};
// Thread-local blocking
AUKN_SYM OutputOfResult OutputOf(StartupParameters &&parameters,
AuOptional<Memory::MemoryViewRead> toSend);
AuOptional<Memory::MemoryViewRead> toSend /* TODO: not yet implemented */);
// Thread-local async
// See: IOSleep.hpp, other ILoopSource yields to enter an alertable state, ILoopQueue to enter an alertable state, et al.
// Will attach to a async worker thread, if under an AuAsync thread.
AUKN_SYM AuSPtr<IAsyncOutputOf> OutputOfAsync(StartupParameters &&parameters,
const AuSPtr<IAsyncCallbacks> &pCallbacks);
}

View File

@ -612,7 +612,20 @@ namespace Aurora::Processes
if (length)
{
pResult->result.strStdout += AuString(pResult->stdOutPipe.begin(), pResult->stdOutPipe.begin() + length);
try
{
AU_LOCK_GUARD(pResult->result.lock);
pResult->result.strStdout += AuString(pResult->stdOutPipe.begin(), pResult->stdOutPipe.begin() + length);
}
catch (...)
{
SysPushErrorOutOfSpaceMemory();
pResult->result.bPipeOutOOM = true;
AuResetMember(pResult->pTransactionA);
AuResetMember(pResult->pTransactionSourceA);
return;
}
if (pResult->pCallbacks)
{
pResult->pCallbacks->OnPipeData();
@ -641,7 +654,20 @@ namespace Aurora::Processes
if (length)
{
pResult->result.strStderr += AuString(pResult->stdErrPipe.begin(), pResult->stdErrPipe.begin() + length);
try
{
AU_LOCK_GUARD(pResult->result.lock);
pResult->result.strStderr += AuString(pResult->stdErrPipe.begin(), pResult->stdErrPipe.begin() + length);
}
catch (...)
{
SysPushErrorOutOfSpaceMemory();
pResult->result.bPipeErrOOM = true;
AuResetMember(pResult->pTransactionB);
AuResetMember(pResult->pTransactionSourceB);
return;
}
if (pResult->pCallbacks)
{
pResult->pCallbacks->OnPipeData();